Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Show function help popup in a dialog #1947

Merged
merged 1 commit into from
Aug 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions res/layout/popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/background_tutorial"
android:orientation="vertical" >

<TextView
Expand All @@ -25,14 +24,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dip" />

<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dip"
android:text="@android:string/ok" />
</LinearLayout>

</ScrollView>
37 changes: 14 additions & 23 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@
import android.text.method.LinkMovementMethod;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
Expand All @@ -69,7 +67,6 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Spinner;
Expand Down Expand Up @@ -1778,12 +1775,19 @@ public boolean hasStableIds() {

@SuppressLint("InflateParams")
public static void showHelp(ActivityBase context, View parent, Hook hook) {
LayoutInflater inflator = LayoutInflater.from(context);
View layout = inflator.inflate(R.layout.popup, null);

TextView tvTitle = (TextView) layout.findViewById(R.id.tvTitle);
// Build dialog
Dialog dlgHelp = new Dialog(context);
dlgHelp.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dlgHelp.setTitle(R.string.app_name);
dlgHelp.setContentView(R.layout.popup);
dlgHelp.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, context.getThemed(R.attr.icon_launcher));
dlgHelp.setCancelable(true);

// Set text title
TextView tvTitle = (TextView) dlgHelp.findViewById(R.id.tvTitle);
tvTitle.setText(hook.getName());

// Set text content
String text = hook.getAnnotation();
String[] permissions = hook.getPermissions();
if (permissions != null && permissions.length > 0) {
Expand All @@ -1794,23 +1798,10 @@ public static void showHelp(ActivityBase context, View parent, Hook hook) {
text += TextUtils.join("<br />", permissions);
}

TextView tvInfo = (TextView) layout.findViewById(R.id.tvInfo);
TextView tvInfo = (TextView) dlgHelp.findViewById(R.id.tvInfo);
tvInfo.setText(Html.fromHtml(text));
tvInfo.setMovementMethod(LinkMovementMethod.getInstance());

final PopupWindow popup = new PopupWindow(layout);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setWidth(90 * parent.getWidth() / 100);

Button btnOk = (Button) layout.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (popup.isShowing())
popup.dismiss();
}
});

popup.showAtLocation(parent, Gravity.CENTER, 0, 0);
dlgHelp.show();
}
}