diff --git a/app/src/main/java/com/allen/appmanager/MainActivity.java b/app/src/main/java/com/allen/appmanager/MainActivity.java index 529df75..ae78d2d 100644 --- a/app/src/main/java/com/allen/appmanager/MainActivity.java +++ b/app/src/main/java/com/allen/appmanager/MainActivity.java @@ -57,6 +57,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; + public class MainActivity extends AppCompatActivity { private RecyclerView mRecyclerView; @@ -68,6 +69,7 @@ public class MainActivity extends AppCompatActivity { private float codesize; private float totalsize; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,6 +85,7 @@ protected void onCreate(Bundle savedInstanceState) { Observable> observable = Observable.create(new ObservableOnSubscribe>() { @Override public void subscribe(ObservableEmitter> appInfo) throws Exception { + appInfo.onNext(queryAppInfo()); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); diff --git a/app/src/main/java/com/allen/appmanager/SideLetterBar.java b/app/src/main/java/com/allen/appmanager/SideLetterBar.java new file mode 100644 index 0000000..0ae81d3 --- /dev/null +++ b/app/src/main/java/com/allen/appmanager/SideLetterBar.java @@ -0,0 +1,171 @@ +/* + * + * * Copyright 2017 [AllenCoderr] + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package com.allen.appmanager; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.widget.TextView; + + +public class SideLetterBar extends View { + private String[] b = {"A", "B", "D", "F", "H", "J", "M", "N", "O", "R", "T", "X", "Y",}; + private int choose = -1; + private Paint paint = new Paint(); + private boolean showBg = false; + private OnLetterChangedListener onLetterChangedListener; + private TextView overlay; + private float startY; + private int singleHeight; + + public String[] getB() { + return b; + } + + public void setB(final String[] b) { + this.b = b; + invalidate(); + + } + + public SideLetterBar(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public SideLetterBar(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SideLetterBar(Context context) { + super(context); + } + + /** + * 设置悬浮的textview + * + * @param overlay + */ + public void setOverlay(TextView overlay) { + this.overlay = overlay; + } + + @SuppressWarnings("deprecation") + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (showBg) { + canvas.drawColor(Color.TRANSPARENT); + } + + int height = getHeight(); + paint.setTextSize(getResources().getDimension(R.dimen.side_letter_bar_letter_size)); + paint.setColor(getResources().getColor(R.color.gray)); + paint.setAntiAlias(true); + + int width = getWidth(); + singleHeight = (int) (Util.calcTextHeight(paint, "A") + Util.dp2px(getContext(), 8)); + startY = (float) ((height - singleHeight * b.length) / 2.0); + for (int i = 0; i < b.length; i++) { + paint.setTextSize(getResources().getDimension(R.dimen.side_letter_bar_letter_size)); + paint.setColor(getResources().getColor(R.color.gray)); + paint.setAntiAlias(true); + if (i == choose) { + paint.setColor(getResources().getColor(R.color.gray_deep)); +// candlePaint.setFakeBoldText(true); //加粗 + } + float xPos = width / 2 - paint.measureText(b[i]) / 2; + float yPos = singleHeight * i + startY; + canvas.drawText(b[i], xPos, yPos, paint); + paint.reset(); + } + + } + + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + final int action = event.getAction(); + final float y = event.getY(); + final int oldChoose = choose; + final OnLetterChangedListener listener = onLetterChangedListener; +// final int c = (int) (y / getHeight() * b.length); + final int c = (int) ((y - startY) / singleHeight); + if (c<0||c>b.length-1){ + overlay.setVisibility(GONE); + return true; + } + + switch (action) { + case MotionEvent.ACTION_DOWN: + showBg = true; + if (oldChoose != c && listener != null) { + if (c >= 0 && c < b.length) { + listener.onLetterChanged(b[c]); + choose = c; + invalidate(); + if (overlay != null) { + overlay.setVisibility(VISIBLE); + overlay.setText(b[c]); + } + } + } + + break; + case MotionEvent.ACTION_MOVE: + if (oldChoose != c && listener != null) { + if (c >= 0 && c < b.length) { + listener.onLetterChanged(b[c]); + choose = c; + invalidate(); + if (overlay != null) { + overlay.setVisibility(VISIBLE); + overlay.setText(b[c]); + } + } + } + break; + case MotionEvent.ACTION_UP: + showBg = false; + choose = -1; + invalidate(); + if (overlay != null) { + overlay.setVisibility(GONE); + } + break; + } + return true; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + return super.onTouchEvent(event); + } + + public void setOnLetterChangedListener(OnLetterChangedListener onLetterChangedListener) { + this.onLetterChangedListener = onLetterChangedListener; + } + + public interface OnLetterChangedListener { + void onLetterChanged(String letter); + } + +} diff --git a/app/src/main/java/com/allen/appmanager/Util.java b/app/src/main/java/com/allen/appmanager/Util.java new file mode 100644 index 0000000..af6522b --- /dev/null +++ b/app/src/main/java/com/allen/appmanager/Util.java @@ -0,0 +1,48 @@ +/* + * + * * Copyright 2017 [AllenCoderr] + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package com.allen.appmanager; + +import android.content.Context; +import android.graphics.Paint; +import android.graphics.Rect; + +/** + * Created by Administrator on 2017/4/26. + */ + +class Util { + /** + * calculates the approximate height of a text, depending on a demo text + * avoid repeated calls (e.g. inside drawing methods) + * + * @param paint + * @param demoText + * @return + */ + public static int calcTextHeight(Paint paint, String demoText) { + + Rect r = new Rect(); + paint.getTextBounds(demoText, 0, demoText.length(), r); + return r.height(); + } + public static float dp2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (dpValue * scale + 0.5f); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ee96da3..5312d53 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,18 +17,52 @@ ~ */ --> - + - + android:id="@+id/relativeLayout" + tools:showIn="@layout/activty_getsymbols"> + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ab233c0..86e40e8 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -21,4 +21,6 @@ #3F51B5 #303F9F #FF4081 + #33fff0 + #3355ff diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index ddb550c..5896f2b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -23,4 +23,5 @@ 16dp 16dp 16dp + 12sp