Skip to content

Commit

Permalink
adding apps feature
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzaczek committed May 11, 2014
1 parent 399761c commit 6b1b545
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 2 deletions.
5 changes: 4 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<activity
android:name=".MissedCallsActivity"
android:screenOrientation="portrait" />
</application>
<activity
android:name=".AppsActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions res/layout/apps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
android:id="@+id/txtMain"
style="@style/Main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/apps" />

<TextView
android:id="@+id/txtHelp"
style="@style/Help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtMain"
android:gravity="center"
android:text="@string/main_help" />

</RelativeLayout>
3 changes: 2 additions & 1 deletion res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="dialer">Wählscheibe</string>
<string name="missedcalls">Verpasste Anrufe</string>
<string name="sms">SMS</string>
<string name="apps">Anwendungen</string>
<string name="currenttime">Uhrzeit</string>
<string name="home">Daheim</string>
<string name="cell">Mobil</string>
Expand All @@ -18,6 +19,6 @@
<string name="not_implemented_yet">noch nicht implementiert</string>
<string name="main_help">Bewegen Sie den Finger über den Bildschrim hinauf oder hinunter um einen Eintrag zu wählen. Doppeltes Tippen wählt den aktuellen Eintrag aus.</string>
<string name="phonebook_help">Bewegen Sie den Finger über den Bildschrim hinauf oder hinunter um einen Eintrag zu wählen. Doppeltes Tippen wählt den aktuellen Eintrag aus.</string>
<string name="time_format">\'Es ist \'HH\' Uhr \'mm\' am \'dd\' \'MMMM</string>
<string name="time_format">\'Es ist \'HH\' Uhr \'mm\' am \'dd\' \'MMMM</string>

</resources>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="dialer">Dialer</string>
<string name="missedcalls">missed calls</string>
<string name="sms">messages</string>
<string name="apps">Applications</string>
<string name="currenttime">current time</string>
<string name="home">home</string>
<string name="cell">cell</string>
Expand Down
61 changes: 61 additions & 0 deletions src/net/zaczek/launcherforblind/AppsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.zaczek.launcherforblind;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.zaczek.launcherforblind.activitysupport.AbstractArrayActivity;
import net.zaczek.launcherforblind.listentries.AppListEntry;
import net.zaczek.launcherforblind.listentries.ListEntry;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;

public class AppsActivity extends AbstractArrayActivity {
private static final String TAG = "launcherforblind";

private TextView txtMain;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
setContentView(R.layout.apps);

txtMain = (TextView) findViewById(R.id.txtMain);
}

@Override
protected ListEntry[] getList() {
Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
homeIntent.addCategory(Intent.CATEGORY_LAUNCHER);

PackageManager pm = this.getPackageManager();
List<AppListEntry> result = new ArrayList<AppListEntry>();

for (ResolveInfo info : pm.queryIntentActivities(homeIntent, 0)) {
final ActivityInfo appInfo = info.activityInfo;
if (!appInfo.packageName.equals("net.zaczek.launcherforblind")) {
String lb = info.loadLabel(pm).toString();
if (TextUtils.isEmpty(lb)) {
lb = info.activityInfo.name.toString();
}
result.add(new AppListEntry(lb, this, info));
}
}

Collections.sort(result);

return result.toArray(new ListEntry[0]);
}

@Override
protected void giveFeedback(String label) {
txtMain.setText(label);
}
}
2 changes: 2 additions & 0 deletions src/net/zaczek/launcherforblind/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected ListEntry[] getList() {
DialerActivity.class),
new NavigatorListEntry(getString(R.string.missedcalls), this,
MissedCallsActivity.class),
new NavigatorListEntry(getString(R.string.apps), this,
AppsActivity.class),
// new NavigatorListEntry(getString(R.string.sms), this, null),
new TimeListEntry(getString(R.string.currenttime),
getString(R.string.time_format)), };
Expand Down
33 changes: 33 additions & 0 deletions src/net/zaczek/launcherforblind/listentries/AppListEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.zaczek.launcherforblind.listentries;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;

public class AppListEntry extends AbstractListEntry implements Comparable<AppListEntry> {
private ResolveInfo mInfo;
private Context mCtx;

public AppListEntry(String label, Context ctx, ResolveInfo info) {
super(label);
mCtx = ctx;
mInfo = info;
}

@Override
public String getTextToSay() {
return null;
}

@Override
public void onSelected() {
final Intent i = mCtx.getPackageManager().getLaunchIntentForPackage(
mInfo.activityInfo.packageName);
mCtx.startActivity(i);
}

@Override
public int compareTo(AppListEntry another) {
return getLabel().compareTo(another.getLabel());
}
}

0 comments on commit 6b1b545

Please sign in to comment.