Skip to content

Commit

Permalink
1.12 支持键盘和遥控器的回车/空格的按键支持
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan committed Jan 5, 2024
1 parent d658274 commit 9a3687d
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 178 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.tumuyan.fixedplay"
minSdkVersion 9
targetSdkVersion 29
versionCode 12
versionName "1.11"
versionCode 13
versionName "1.12"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
100 changes: 52 additions & 48 deletions app/src/main/java/com/tumuyan/fixedplay/App/ItemAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public void setUri(String uri) {
public View getView(final int position, View convertView, final ViewGroup parent) {
final Item item = getItem(position);
View view = LayoutInflater.from(getContext()).inflate(layoutId, parent, false);
final String packageName=item.getPackageName();
final String className=item.getClassName();
final String Name=item.getName();

String _class, _package, _name;
if(className.length()<1) {
_name=Name;
_package=packageName;
}else if(className.contains(packageName)){
_class=className.replace(packageName,"");
_package=packageName;
_name=Name+"("+_class+")";
}else {
_name=Name;
_package=packageName+"\n"+className;
final String packageName = item.getPackageName();
final String className = item.getClassName();
final String Name = item.getName();

String _class, _package, _name;
if (className.length() < 1) {
_name = Name;
_package = packageName;
} else if (className.contains(packageName)) {
_class = className.replace(packageName, "");
_package = packageName;
_name = Name + "(" + _class + ")";
} else {
_name = Name;
_package = packageName + "\n" + className;
}

((ImageView) view.findViewById(R.id.item_img)).setImageDrawable(item.getAppIcon());
Expand All @@ -74,47 +74,51 @@ public View getView(final int position, View convertView, final ViewGroup parent
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
select(Name,packageName,className);
}
});
return view;
}



public void select(String Name, String packageName, String className){

if(mode.equals("2nd")){
SharedPreferences.Editor editor = getContext(). getSharedPreferences("setting",MODE_MULTI_PROCESS).edit();
editor.putString("app_2nd", packageName);
editor.putString("label_2nd", Name);
editor.putString("class_2nd",className);
editor.commit();
Intent intent=new Intent(getContext() ,SettingActivity.class);
getContext().startActivity(intent);
}else{
PackageManager pm =getContext(). getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(packageName);

if(mode.equals("2nd")){
if (intent != null) {

{
SharedPreferences.Editor editor = getContext(). getSharedPreferences("setting",MODE_MULTI_PROCESS).edit();
editor.putString("app_2nd", packageName);
editor.putString("label_2nd", Name);
editor.putString("class_2nd",className);
editor.putString("app", packageName);
editor.putString("label", Name);
editor.putString("class",className);
editor.putString("uri",uri);
editor.putString("mode",mode);
editor.commit();
Intent intent=new Intent(getContext() ,SettingActivity.class);
getContext().startActivity(intent);
}else{
PackageManager pm =getContext(). getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(packageName);

if (intent != null) {

{
SharedPreferences.Editor editor = getContext(). getSharedPreferences("setting",MODE_MULTI_PROCESS).edit();
editor.putString("app", packageName);
editor.putString("label", Name);
editor.putString("class",className);
editor.putString("uri",uri);
editor.putString("mode",mode);
editor.commit();
}

// getContext().startActivity(intent);
intent=new Intent(getContext() ,SettingActivity.class);
getContext().startActivity(intent);

}else{
Toast.makeText(getContext(),R.string.error_could_not_start,Toast.LENGTH_SHORT).show();
}

}

// getContext().startActivity(intent);
intent=new Intent(getContext() ,SettingActivity.class);
getContext().startActivity(intent);


}else{
Toast.makeText(getContext(),R.string.error_could_not_start,Toast.LENGTH_SHORT).show();
}
});

return view;
}


}


Expand Down
131 changes: 73 additions & 58 deletions app/src/main/java/com/tumuyan/fixedplay/App/SelectOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -33,43 +34,43 @@
import java.util.List;


public class SelectOne extends Activity {
public class SelectOne extends Activity {
// Adapter显示项目(筛选后
private List<Item> list = new ArrayList<>();
// 原始搜索结果
private List<Item> listOrgin=new ArrayList<>();
private List<Item> listOrgin = new ArrayList<>();

private ListView listView;
private ProgressBar progressBar;
private String _mode,_action,_uri;
private String _mode, _action, _uri;

private View SearchBox;
private EditText SearchText;
private Button SearchButton;
ItemAdapter itemAdapter;
private Drawable defaultIcon;
ItemAdapter itemAdapter;
private Drawable defaultIcon;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.applist_activity);
progressBar=(ProgressBar)findViewById(R.id.progressBar);
SearchBox=(View)findViewById(R.id.searchBox);
SearchButton=(Button)findViewById(R.id.button_filter);
SearchText=(EditText) findViewById(R.id.editText_filter);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
SearchBox = (View) findViewById(R.id.searchBox);
SearchButton = (Button) findViewById(R.id.button_filter);
SearchText = (EditText) findViewById(R.id.editText_filter);
SearchBox.setVisibility(View.GONE);
Intent intent=getIntent();
_mode=intent.getStringExtra("_mode");
_action=intent.getStringExtra("_action");
_uri=intent.getStringExtra("_uri");
defaultIcon=getResources().getDrawable(R.drawable.unknow);
Intent intent = getIntent();
_mode = intent.getStringExtra("_mode");
_action = intent.getStringExtra("_action");
_uri = intent.getStringExtra("_uri");
defaultIcon = getResources().getDrawable(R.drawable.unknow);

new Thread(new Runnable() {
@Override
public void run() {
// getAppList();
loadAllApps( makeIntent());
list.addAll(listOrgin);
loadAllApps(makeIntent());
list.addAll(listOrgin);

itemAdapter = new ItemAdapter(SelectOne.this, R.layout.applist_item, list);
itemAdapter.setMode(_mode);
Expand All @@ -83,7 +84,28 @@ public void run() {
listView.setAdapter(itemAdapter);
progressBar.setVisibility(View.GONE);
SearchBox.setVisibility(View.VISIBLE);
}


listView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP)
{

if ( keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {

int selectedItemPosition = listView.getSelectedItemPosition();
Log.i("App SelectorOne", "Keycode = " + keyCode + ", cursorPosition = " + selectedItemPosition);
Item item = list.get(selectedItemPosition);
itemAdapter.select(item.getName(), item.getPackageName(), item.getClassName() );
return true;
}
}
return false;
}
});

}

});

Expand Down Expand Up @@ -117,25 +139,23 @@ public void onClick(View view) {
//
// }

private void doSearch (String str){
list.clear();
for(int i=0;i<listOrgin.size();i++){
Item item=listOrgin.get(i);
if(item.getClassName().contains(str) ||
item.getPackageName().contains(str)||
item.getName().contains(str)){
list.add(item);
}
}
Log.w("search", str+" get"+list.size());
itemAdapter.notifyDataSetChanged();

private void doSearch(String str) {
list.clear();
for (int i = 0; i < listOrgin.size(); i++) {
Item item = listOrgin.get(i);
if (item.getClassName().contains(str) ||
item.getPackageName().contains(str) ||
item.getName().contains(str)) {
list.add(item);
}

}
Log.w("search", str + " get" + list.size());
itemAdapter.notifyDataSetChanged();
}


@Override
protected void onPause(){
protected void onPause() {
super.onPause();
this.finish();
}
Expand Down Expand Up @@ -184,10 +204,9 @@ private void loadAllApps() {
PackageManager pm = getPackageManager();



for(ResolveInfo r:mApps){
Drawable ic=r.loadIcon((pm));
if(ic==null) ic=defaultIcon;
for (ResolveInfo r : mApps) {
Drawable ic = r.loadIcon((pm));
if (ic == null) ic = defaultIcon;

Item item = new Item(
r.loadLabel(pm).toString(),
Expand All @@ -200,7 +219,7 @@ private void loadAllApps() {

}

// 唯一在用的新方法
// 唯一在用的新方法
private void loadAllApps(Intent intent) {
List<ResolveInfo> mApps;
mApps = new ArrayList<>();
Expand All @@ -209,8 +228,8 @@ private void loadAllApps(Intent intent) {

PackageManager pm = getPackageManager();
for (ResolveInfo r : mApps) {
Drawable ic=r.loadIcon((pm));
if(ic==null) ic=defaultIcon;
Drawable ic = r.loadIcon((pm));
if (ic == null) ic = defaultIcon;

Item item = new Item(
r.loadLabel(pm).toString(),
Expand All @@ -220,62 +239,58 @@ private void loadAllApps(Intent intent) {
);
listOrgin.add(item);
}
Log.w("load",""+listOrgin.size());
}catch (Exception e){
Log.w("load", "" + listOrgin.size());
} catch (Exception e) {
e.printStackTrace();
}

}

private Intent makeIntent(){
private Intent makeIntent() {

switch (_mode){
switch (_mode) {
case "r2":
case "r1":
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
return mainIntent;
case "uri":
{
case "uri": {
Uri uri = Uri.parse(_uri);
Intent it = new Intent(Intent.ACTION_VIEW,uri);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
return it;
}

case "uri_dail":
{
case "uri_dail": {
Uri uri = Uri.parse(_uri);
Intent it = new Intent(Intent.ACTION_DIAL, uri);
return it;
}

case "uri_file":
{ File f=(new File(_uri));
case "uri_file": {
File f = (new File(_uri));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(Uri.fromFile(f), "*/*");
return intent;
}

case "2nd":
{
case "2nd": {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.setAction(Intent.ACTION_MAIN);
// intent.setAction(Intent.ACTION_VIEW);
intent.addCategory("android.intent.category.HOME" );
intent.addCategory("android.intent.category.HOME");
return intent;

}
case "short_cut":
{
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
case "short_cut": {
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);

return shortcutsIntent;
}

}
return null;
return null;

}

Expand Down
Loading

0 comments on commit 9a3687d

Please sign in to comment.