Skip to content

Commit

Permalink
fix. FTP click no respond
Browse files Browse the repository at this point in the history
fix. Wifi item crash
fix. refresh app redundancy
  • Loading branch information
Modificator committed Dec 22, 2019
1 parent d7fc1c0 commit 1ccbe2d
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
debug {
debuggable true
zipAlignEnabled true
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SHUTDOWN" />
<uses-permission android:name="android.permission.REBOOT" />
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>-->
<!-- <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>-->

<application
android:name=".App"
Expand Down Expand Up @@ -61,11 +63,11 @@
</receiver>
<receiver
android:name=".ftpservice.FTPReceiver"
android:exported="true">
<intent-filter>
<action android:name="cn.modificator.launcher.ftpservice.FTPReceiver.ACTION_START_FTPSERVER" />
<action android:name="cn.modificator.launcher.ftpservice.FTPReceiver.ACTION_STOP_FTPSERVER" />
</intent-filter>
android:exported="false">
<!-- <intent-filter>-->
<!-- <action android:name="cn.modificator.launcher.ftpservice.FTPReceiver.ACTION_START_FTPSERVER" />-->
<!-- <action android:name="cn.modificator.launcher.ftpservice.FTPReceiver.ACTION_STOP_FTPSERVER" />-->
<!-- </intent-filter>-->
</receiver>

<activity android:name=".CrashDetailPage"
Expand Down
23 changes: 18 additions & 5 deletions app/src/main/java/cn/modificator/launcher/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.modificator.launcher;

import android.Manifest;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
Expand All @@ -12,16 +13,20 @@
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.io.File;
import java.util.Calendar;

import cn.modificator.launcher.ftpservice.FTPReceiver;
import cn.modificator.launcher.ftpservice.FTPService;
import cn.modificator.launcher.model.AdminReceiver;
import cn.modificator.launcher.model.AppDataCenter;
import cn.modificator.launcher.widgets.BatteryView;
Expand Down Expand Up @@ -54,6 +59,7 @@ public class Launcher extends Activity {
DevicePolicyManager policyManager;
File iconFile;
boolean isChina = true;
FTPReceiver ftpReceiver = new FTPReceiver();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -66,8 +72,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
}


isChina = getResources().getConfiguration().locale.getCountry().equals("CN");

initView();
//Log.e("----",Arrays.toString(iconFile.list()));
}
Expand All @@ -85,15 +91,16 @@ private void initView() {
// launcherView.setIconReplaceFile(Arrays.asList(iconFile.list()));
launcherView.setHideAppPkg(config.getHideApps());
launcherView.setHideDivider(config.getDividerHideStatus());
launcherView.setFontSize(config.getFontSize());

dataCenter = new AppDataCenter(this);
dataCenter.setHideApps(config.getHideApps());

dataCenter.setPageStatus(pageStatus);
dataCenter.setLauncherView(launcherView);
//加载之前保存的桌面数据
updateColNum(config.getColNum());
updateRowNum(config.getRowNum());
launcherView.setFontSize(config.getFontSize());

findViewById(R.id.lastPage).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -166,14 +173,14 @@ public void toLast() {
}

private void updateRowNum(int rowNum) {
dataCenter.setRowNum(rowNum);
launcherView.setRowNum(rowNum);
dataCenter.setRowNum(rowNum);
config.setRowNum(rowNum);
}

private void updateColNum(int colNum) {
dataCenter.setColNum(colNum);
launcherView.setColNum(colNum);
dataCenter.setColNum(colNum);
config.setColNum(colNum);
}

Expand Down Expand Up @@ -206,6 +213,12 @@ public void onReceive(Context context, Intent intent) {
if (launcherView != null) launcherView.refreshReplaceIcon();
detectionUSB();

IntentFilter ftpIntentFilter = new IntentFilter(FTPService.ACTION_START_FTPSERVER);
ftpIntentFilter.addAction(FTPService.ACTION_STOP_FTPSERVER);
registerReceiver(ftpReceiver,ftpIntentFilter);
// if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
// requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION},0 );
// }
}

/**
Expand Down Expand Up @@ -239,7 +252,7 @@ protected void onPause() {
unregisterReceiver(batteryLevelRcvr);
unregisterReceiver(timeListener);
unregisterReceiver(usbReceiver);

unregisterReceiver(ftpReceiver);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void run() {
server.start();
sendBroadcast(new Intent(FTPService.ACTION_STARTED));
} catch (Exception e) {
e.printStackTrace();
sendBroadcast(new Intent(FTPService.ACTION_FAILEDTOSTART));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.net.Uri;
import android.os.PowerManager;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -29,8 +30,10 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Observer;
import java.util.Set;

import cn.modificator.launcher.Config;
import cn.modificator.launcher.Launcher;
import cn.modificator.launcher.R;
import cn.modificator.launcher.Utils;
Expand Down Expand Up @@ -121,6 +124,23 @@ public void setTouchListener(TouchListener touchListener) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
dragDistance = Math.min(getMeasuredWidth(), getMeasuredHeight()) / 6f;

for (int i = 0; i < ROW_NUM; i++) {
for (int j = 0; j < COL_NUM; j++) {
/*if (COL_NUM * i + j == dataList.size())
break AddView;*/
int childLeft = j * getItemWidth();// + (j * dividerSize);
int childRight = (j + 1) * getItemWidth();// + (j * dividerSize);
int childTop = i * getItemHeight();// + (i * dividerSize);
int childBottom = (i + 1) * getItemHeight();// + (i * dividerSize);
// view.measure(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

getChildAt(i*COL_NUM+j).layout(childLeft, childTop, childRight, childBottom);
}
}
if (dragDistance>0){
return;
}
observable.deleteObservers();
removeAllViews();
AddView:
Expand All @@ -134,8 +154,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childTop = i * getItemHeight();// + (i * dividerSize);
int childBottom = (i + 1) * getItemHeight();// + (i * dividerSize);
// view.measure(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
view.measure(makeMeasureSpec(getItemWidth(), EXACTLY),
makeMeasureSpec(getItemHeight(), EXACTLY));

view.layout(childLeft, childTop, childRight, childBottom);
if (COL_NUM * i + j >= dataList.size()) {
if (COL_NUM * i + j == dataList.size()) {
Expand Down Expand Up @@ -254,10 +273,79 @@ else if (i == ROW_NUM - 1)
}
}

private void resetIconLayout(){
observable.deleteObservers();
removeAllViews();
for (int i = 0; i < ROW_NUM * COL_NUM; i++) {
View itemView = LayoutInflater.from(getContext()).inflate(R.layout.launcher_item, this, false);
observable.addObserver((Observer) itemView.findViewById(R.id.appName));
((TextView)itemView.findViewById(R.id.appName)).setTextSize(TypedValue.COMPLEX_UNIT_SP, Config.fontSize);

if (hideDivider) {
itemView.setBackgroundResource(R.drawable.app_item_final);
} else if (i==ROW_NUM*COL_NUM-1) {
itemView.setBackgroundResource(R.drawable.app_item_final);
}else if (i%COL_NUM==COL_NUM-1){
itemView.setBackgroundResource(R.drawable.app_item_right);
}else if (i>(ROW_NUM-1)*COL_NUM-1){
itemView.setBackgroundResource(R.drawable.app_item_bottom);
} else{
itemView.setBackgroundResource(R.drawable.app_item_normal);
}
// if (COL_NUM * i + j < dataList.size() + 2) {
// if (hideDivider) {
// view.setBackgroundResource(R.drawable.app_item_final);
// } else if (j == COL_NUM - 1 && i == ROW_NUM - 1) {
// view.setBackgroundResource(R.drawable.app_item_final);
// } else if (j == COL_NUM - 1)
// view.setBackgroundResource(R.drawable.app_item_right);
// else if (i == ROW_NUM - 1)
// view.setBackgroundResource(R.drawable.app_item_bottom);
// else if (!hideDivider)
// view.setBackgroundResource(R.drawable.app_item_normal);
// }
addView(itemView);
}
refreshIconData();
}

private void refreshIconData(){
int position;
View itemView;
for (int i = 0; i < ROW_NUM; i++) {
for (int j = 0; j < COL_NUM; j++) {
position = i*COL_NUM+j;
itemView = getChildAt(position);
if (itemView == null) {
return;
}
if (position<dataList.size()&&position<getChildCount()) {
if (iconReplacePkg.contains(dataList.get(COL_NUM * i + j).activityInfo.packageName)) {
((ImageView) itemView.findViewById(R.id.appImage)).setImageURI(Uri.fromFile(iconReplaceFile.get(iconReplacePkg.indexOf(dataList.get(COL_NUM * i + j).activityInfo.packageName))));
} else {
((ImageView) itemView.findViewById(R.id.appImage)).setImageDrawable(dataList.get(COL_NUM * i + j).loadIcon(packageManager));
}
((TextView) itemView.findViewById(R.id.appName)).setText(dataList.get(COL_NUM * i + j).loadLabel(packageManager));
itemView.setOnClickListener(new ItemClickListener(COL_NUM * i + j));
itemView.setOnLongClickListener(new ItemLongClickListener(COL_NUM * i + j));
itemView.findViewById(R.id.menu_delete).setOnClickListener(new ItemClickListener(COL_NUM * i + j));
itemView.findViewById(R.id.menu_hide).setOnClickListener(new ItemHideClickListener(COL_NUM * i + j));
itemView.setVisibility(VISIBLE);
}else{
((TextView) itemView.findViewById(R.id.appName)).setText("");
((ImageView) itemView.findViewById(R.id.appImage)).setImageDrawable(null);
itemView.setLongClickable(false);
itemView.setClickable(false);
itemView.setVisibility(GONE);
}
}
}
}

public void setAppList(List<ResolveInfo> appList) {
dataList.clear();
dataList.addAll(appList);
requestLayout();
refreshIconData();
}


Expand All @@ -274,12 +362,12 @@ private int getItemWidth() {

public void setColNum(int colNum) {
this.COL_NUM = colNum;
requestLayout();
resetIconLayout();
}

public void setRowNum(int rowNum) {
this.ROW_NUM = rowNum;
requestLayout();
resetIconLayout();
}

private int getAdjustedHeight() {
Expand All @@ -304,6 +392,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);

int itemWidthMeasureSpec =makeMeasureSpec(getItemWidth(),EXACTLY);
int itemHeightMeasureSpec = makeMeasureSpec(getItemHeight(),EXACTLY);
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).measure(itemWidthMeasureSpec,itemHeightMeasureSpec );
}
}

private class ItemClickListener implements OnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public ObserverFontTextView(Context context, @Nullable AttributeSet attrs, int d
@Override
public void update(Observable o, Object arg) {
setTextSize(TypedValue.COMPLEX_UNIT_SP, (Float) arg);
requestLayout();
// requestLayout();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
Expand Down Expand Up @@ -173,7 +174,18 @@ public void onReceive(Context context, Intent intent) {
case CONNECTED:
Log.e("APActivity", "CONNECTED");
// appName.setSingleLine(false);
appName.setText(getResources().getString(R.string.wifi_status_connected, networkInfo.getExtraInfo().replaceFirst("\"", "\n").replace("\"", "")));
String wifiName = "";
if (networkInfo.getExtraInfo()!=null) {
wifiName = networkInfo.getExtraInfo().replace("\"", "");
}
if (wifiName.isEmpty()){
wifiName = wifiManager.getConnectionInfo().getSSID().replace("\"","");
}
if (!TextUtils.isEmpty(wifiName)){
wifiName = "\n"+wifiName;
}
appName.setText(getResources().getString(R.string.wifi_status_connected, wifiName));

break;
case CONNECTING:
Log.e("APActivity", "CONNECTING");
Expand Down

0 comments on commit 1ccbe2d

Please sign in to comment.