Example usage for android.view ContextThemeWrapper ContextThemeWrapper

List of usage examples for android.view ContextThemeWrapper ContextThemeWrapper

Introduction

In this page you can find the example usage for android.view ContextThemeWrapper ContextThemeWrapper.

Prototype

public ContextThemeWrapper(Context base, Resources.Theme theme) 

Source Link

Document

Creates a new context wrapper with the specified theme.

Usage

From source file:com.juick.android.ThreadActivity.java

private void previewAndSendReply(final String msg) {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    if (sp.getBoolean("previewReplies", false)) {
        final TextView tv = new TextView(this);
        JuickMessage jm = new JuickMessage();
        jm.User = new JuickUser();
        jm.User.UName = "You";
        jm.Text = msg;/* w  w w . j  av a  2  s. c om*/
        jm.tags = new Vector<String>();
        if (rid != 0) {
            // insert destination user name
            JuickMessage reply = tf.findReply(tf.getListView(), rid);
            if (reply != null) {
                jm.Text = "@" + reply.User.UName + " " + jm.Text;
            }
        }
        JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter.formatMessageText(this, jm,
                true);
        tv.setText(parsedMessage.textContent);
        tv.setPadding(10, 10, 10, 10);
        MainActivity.restyleChildrenOrWidget(tv);
        final AlertDialog dialog = new AlertDialog.Builder(
                new ContextThemeWrapper(this, R.style.Theme_Sherlock_Light)).setTitle("Post reply - preview")
                        .setView(tv).setCancelable(true)
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }).setPositiveButton("Post reply", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                sendReplyMain(msg);
                            }
                        }).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface i) {
                tv.setBackgroundColor(JuickMessagesAdapter.getColorTheme(dialog.getContext()).getBackground());
                MainActivity.restyleChildrenOrWidget(tv);
            }
        });
        dialog.show();
    } else {
        sendReplyMain(msg);
    }
}

From source file:pt.aptoide.backupapps.Aptoide.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!isRunning) {

        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

        theme = new ContextThemeWrapper(this, R.style.DialogTheme);

        //         currentAppsList = EnumAppsLists.Backup;

        //         handlingMyapps = new ArrayList<ViewMyapp>();

        queuedFlipperChanges = new ArrayList<EnumAptoideInterfaceTasks>();

        //         swypeDetector = new GestureDetector(new SwypeDetector());
        //         swypeListener = new View.OnTouchListener() {
        //                           @Override
        //                           public boolean onTouch(View v, MotionEvent event) {
        //                              return swypeDetector.onTouchEvent(event);
        //                           }
        //                        };
        //         swyping = new AtomicBoolean(false);
        //         swypeDelayHandler = new Handler();

        synchronizingInstalledApps = new AtomicBoolean(false);
        loadingRepos = new AtomicBoolean(false);
        //         resettingFlipper = new AtomicBoolean(false);
        highPriority = new AtomicBoolean(true);

        makeSureServiceDataIsRunning();//from   w w w.j ava2  s  .  c  om

        isRunning = true;

        setContentView(R.layout.aptoide);

        //         searchView = (ImageView) findViewById(R.id.search_button);
        //         searchView.setOnTouchListener(new SearchClickListener());

        //         previousViewArrow = (ImageView) findViewById(R.id.previous);
        //         previousViewArrow.setOnClickListener(new OnPreviousClickedListener());
        //         previousViewArrow.setVisibility(View.INVISIBLE);

        //         previousListTitle = (TextView) findViewById(R.id.previous_title);
        //         previousListTitle.setText(getString(R.string.available));
        //         previousListTitle.setOnClickListener(new OnPreviousClickedListener());
        //         previousListTitle.setVisibility(View.INVISIBLE);
        //         currentListTitle = (TextView) findViewById(R.id.current_title);
        //         currentListTitle.setText(getString(R.string.available));
        //         currentListTitle.setClickable(false);
        //         nextListTitle = (TextView) findViewById(R.id.next_title);
        //         nextListTitle.setText(getString(R.string.installed));
        //         nextListTitle.setOnClickListener(new OnNextClickedListener());

        //         nextViewArrow = (ImageView) findViewById(R.id.next);
        //         nextViewArrow.setOnClickListener(new OnNextClickedListener());

        //         View categoriesView = LinearLayout.inflate(this, R.layout.apps_list, appsListFlipper);
        View availableView = LinearLayout.inflate(this, R.layout.list_apps, appsListPager);
        View installedView = LinearLayout.inflate(this, R.layout.list_apps, appsListPager);
        //         View updatableView = LinearLayout.inflate(this, R.layout.list_apps, appsListFlipper);

        //         emptyCategoriesList = categoriesView.findViewById(android.R.id.empty);
        //         emptyCategoriesList.setVisibility(View.GONE);
        //         emptyAvailableAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        emptyAvailableAppsList = availableView.findViewById(android.R.id.empty);
        emptyAvailableAppsList.setVisibility(View.GONE);
        emptyAvailableAppsList.setTag(EnumAppsLists.RESTORE);
        //         emptyInstalledAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        emptyInstalledAppsList = installedView.findViewById(android.R.id.empty);
        emptyInstalledAppsList.setVisibility(View.GONE);
        emptyInstalledAppsList.setTag(EnumAppsLists.BACKUP);
        //         emptyUpdatableAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        //         emptyUpdatableAppsList = updatableView.findViewById(android.R.id.empty);
        //         emptyUpdatableAppsList.setVisibility(View.GONE);
        //         emptyUpdatableAppsList.setTag(EnumAppsLists.Updates);

        //         loadingCategoriesList = categoriesView.findViewById(R.id.loading);
        //         loadingAvailableAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        loadingAvailableAppsList = availableView.findViewById(R.id.loading);
        loadingAvailableAppsList.setTag(EnumAppsLists.RESTORE);
        loadingAppsTitle = loadingAvailableAppsList.findViewById(R.id.loading_title);
        loadingAppsTitleWaitingOnServer = loadingAvailableAppsList
                .findViewById(R.id.loading_title_waiting_on_server);
        loadingAvailableAppsUnknownProgress = (ProgressBar) loadingAvailableAppsList
                .findViewById(R.id.loading_bar);
        loadingAvailableAppsProgress = (ProgressBar) loadingAvailableAppsList
                .findViewById(R.id.loading_progress_bar);
        loadingAvailableAppsProgressCompletionTarget = new AtomicInteger(0);
        loadingAvailableAppsProgressCurrent = new AtomicInteger(0);
        //         loadingInstalledAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        loadingInstalledAppsList = installedView.findViewById(R.id.loading);
        loadingInstalledAppsList.setTag(EnumAppsLists.BACKUP);
        //         loadingUpdatableAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        //         loadingUpdatableAppsList = updatableView.findViewById(R.id.loading);
        //         loadingUpdatableAppsList.setTag(EnumAppsLists.Updates);

        //         categoriesListView = new ListView(this);
        //         categoriesListView = (ListView) categoriesView.findViewById(android.R.id.list);
        //         categoriesListView.setCacheColorHint(Color.TRANSPARENT);
        //         categoriesListView.setOnTouchListener(swypeListener);
        //         categoriesListView.setOnItemClickListener(this);
        //         categoriesListView.setTag(EnumAppsLists.Available);
        //         categoriesListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);

        //         availableAppsListView = new ListView(this);
        availableAppsListView = (ListView) availableView.findViewById(android.R.id.list);
        availableAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         availableAppsListView.setOnTouchListener(swypeListener);
        availableAppsListView.setOnItemClickListener(this);
        availableAppsListView.setTag(EnumAppsLists.RESTORE);
        availableAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(availableAppsList);

        //         installedAppsListView = new ListView(this);
        installedAppsListView = (ListView) installedView.findViewById(android.R.id.list);
        installedAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         installedAppsListView.setOnTouchListener(swypeListener);
        installedAppsListView.setOnItemClickListener(this);
        installedAppsListView.setTag(EnumAppsLists.BACKUP);
        installedAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(installedAppsList);

        //         updatableAppsListView = new ListView(this);
        //         updatableAppsListView = (ListView) updatableView.findViewById(android.R.id.list);
        //         updatableAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         updatableAppsListView.setOnTouchListener(swypeListener);
        //         updatableAppsListView.setOnItemClickListener(this);
        //         updatableAppsListView.setTag(EnumAppsLists.Updates);
        //         updatableAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(updatableAppsList);

        Button backup = (Button) installedView.findViewById(R.id.action);
        backup.setText(R.string.backup_selected_apps);
        backup.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("Aptoide-AppsBackup", "Clicked on backup");

                //               if(selectedVersion.getRepoUri() != null){
                //                  if(authenticationToken == null){
                //                     try {
                //                        authenticationToken = serviceDataCaller.callGetServerToken();
                //                     } catch (RemoteException e) {
                //                        // TODO Auto-generated catch block
                //                        e.printStackTrace();
                //                     }
                //                  }
                //                  if(authenticationToken == null){
                //                     Log.d("Aptoide-AppsBackup", "No login set");
                //                     DialogLogin loginComments = new DialogLogin(AppInfo.this, serviceDataCaller, DialogLogin.InvoqueNature.NO_CREDENTIALS_SET);
                //                     loginComments.setOnDismissListener(new OnDismissListener() {
                //                        @Override
                //                        public void onDismiss(DialogInterface dialog) {
                //                           addAppVersionComment();
                //                        }
                //                     });
                //                     loginComments.show();
                //                  }else{
                //                     addAppVersionComment();                  
                //                  }
                //               }
                try {
                    authenticationToken = serviceDataCaller.callGetServerToken();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

                ViewListIds uploads = new ViewListIds();

                for (int i = 0; i < installedAdapter.getCount(); i++) {
                    if (((ViewDisplayApplicationBackup) installedAdapter.getItem(i)).isChecked()) {
                        uploads.add(installedAdapter.getItem(i).getAppHashid());
                    }
                }

                if (uploads.size() > 0) {
                    installedAdapter.unselectAll();
                    if (authenticationToken != null) {
                        Intent upload = new Intent(Aptoide.this, Upload.class);
                        upload.putIntegerArrayListExtra("uploads", uploads);
                        startActivity(upload);
                    } else {
                        AptoideLog.d(Aptoide.this, "can't backup with no server login configured");
                        //                  Toast.makeText(Aptoide.this, R.string.login_required, Toast.LENGTH_SHORT).show();
                        login(uploads, EnumAppsLists.BACKUP);
                    }
                }

            }
        });

        Button restore = (Button) availableView.findViewById(R.id.action);
        restore.setText(R.string.restore_selected_apps);
        restore.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.d("Aptoide-AppsBackup", "Clicked on restore");
                try {
                    anyReposInUse = serviceDataCaller.callAnyReposInUse();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

                ViewListIds restores = new ViewListIds();
                ViewDisplayApplicationBackup app;
                for (int i = 0; i < availableAdapter.getCount(); i++) {
                    app = ((ViewDisplayApplicationBackup) availableAdapter.getItem(i));
                    if (app.isChecked()) {
                        restores.add(availableAdapter.getItem(i).getAppHashid());
                        Toast.makeText(Aptoide.this,
                                getString(R.string.restoring_app, availableAdapter.getItem(i).getAppName()),
                                Toast.LENGTH_SHORT).show();
                    }
                }

                availableAdapter.unselectAll();

                if (anyReposInUse) {
                    for (Integer appHashid : restores) {
                        try {
                            serviceDataCaller.callInstallApp(appHashid);
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    AptoideLog.d(Aptoide.this, "can't restore with no repo configured");
                    //                  Toast.makeText(Aptoide.this, R.string.login_required, Toast.LENGTH_SHORT).show();
                    login(restores, EnumAppsLists.RESTORE);
                }
            }
        });

        ArrayList<View> pages = new ArrayList<View>();
        pages.add(installedView);
        pages.add(availableView);

        appsListPager = (ViewPager) findViewById(R.id.list_pager);
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(pages);
        appsListPager.setAdapter(pagerAdapter);

        pageIndicator = (FixedTabsView) findViewById(R.id.indicator);
        pageIndicatorAdapter = new FixedTabsAdapter(this);
        pageIndicator.setAdapter(pageIndicatorAdapter);
        pageIndicator.setViewPager(appsListPager);

        //         appsListFlipper.addView(loadingAvailableAppsList);
        //         appsListFlipper.addView(loadingInstalledAppsList);
        //         appsListFlipper.addView(loadingUpdatableAppsList);
        //         appsListPager.addView(availableView);
        //         appsListPager.addView(installedView);
        //         appsListFlipper.addView(updatableView);
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getThemeForegroundColor(final Context context, int theme) {
    final Context wrapped = theme != 0 ? new ContextThemeWrapper(context, theme) : context;
    final TypedArray a = wrapped.obtainStyledAttributes(new int[] { android.R.attr.colorForeground });
    try {/*w ww  .  j a  va 2 s  . c  om*/
        return a.getColor(0, 0);
    } finally {
        a.recycle();
    }
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    Activity activity = getActivity();/*from w ww .ja  va  2  s .  c  om*/
    int theme = onProvideTheme();
    if (theme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = android.support.v17.leanback.R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mThemeWrapper = themeWrapper;
            } else {
                found = false;
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepListFragment does not have an appropriate theme set.");
        }
    } else if (theme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, theme);
    }
}

From source file:android.support.v7ox.app.WindowDecorActionBar.java

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme_ox, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {//from   w ww  . j a v  a 2 s.co m
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:com.juick.android.MessageMenu.java

protected void runActions() {
    if (!isDialogMode()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final CharSequence[] items = new CharSequence[menuActions.size()];
        for (int j = 0; j < items.length; j++) {
            items[j] = menuActions.get(j).title;
        }/*  w ww.  j a  va 2  s .  co  m*/
        builder.setItems(items, this);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity);
                ColorDrawable divider = new ColorDrawable(
                        colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF));
                alertDialog.getListView().setDivider(divider);
                alertDialog.getListView().setDividerHeight(1);
            }
        });
        alertDialog.show();

        final ListAdapter adapter = alertDialog.getListView().getAdapter();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
        float menuFontScale = 1;
        try {
            menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0"));
        } catch (Exception e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        final boolean compressedMenu = sp.getBoolean("compressedMenu", false);
        final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false);
        final float finalMenuFontScale = menuFontScale;
        final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
        alertDialog.getListView().setAdapter(new ListAdapter() {
            @Override
            public boolean areAllItemsEnabled() {
                return adapter.areAllItemsEnabled();
            }

            @Override
            public boolean isEnabled(int position) {
                return adapter.isEnabled(position);
            }

            @Override
            public void registerDataSetObserver(DataSetObserver observer) {
                adapter.registerDataSetObserver(observer);
            }

            @Override
            public void unregisterDataSetObserver(DataSetObserver observer) {
                adapter.unregisterDataSetObserver(observer);
            }

            @Override
            public int getCount() {
                return items.length;
            }

            @Override
            public Object getItem(int position) {
                return adapter.getItem(position);
            }

            @Override
            public long getItemId(int position) {
                return adapter.getItemId(position);
            }

            @Override
            public boolean hasStableIds() {
                return adapter.hasStableIds();
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View retval = adapter.getView(position, null, parent);
                if (retval instanceof TextView) {
                    TextView tv = (TextView) retval;
                    if (compressedMenu) {
                        int minHeight = (int) ((screenHeight * 0.7) / getCount());
                        tv.setMinHeight(minHeight);
                        tv.setMinimumHeight(minHeight);
                    }
                    if (singleLineMenu) {
                        tv.setSingleLine(true);
                        tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
                    }
                    tv.setTextSize(22 * finalMenuFontScale);
                }
                return retval;
            }

            @Override
            public int getItemViewType(int position) {
                return adapter.getItemViewType(position);
            }

            @Override
            public int getViewTypeCount() {
                return adapter.getViewTypeCount();
            }

            @Override
            public boolean isEmpty() {
                return adapter.isEmpty();
            }
        });
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                new ContextThemeWrapper(activity, R.style.Theme_Sherlock));
        View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null);
        builder.setView(dialogView);
        builder.setCancelable(true);
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        View scrollView = dialogView.findViewById(R.id.scrollView);
        scrollView.getLayoutParams().width = (int) (width * 0.90);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView());
            }
        });
        TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no);
        messageNo.setText(listSelectedItem.getDisplayMessageNo());
        Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url);
        Button singleURL = (Button) dialogView.findViewById(R.id.single_url);
        if (urls != null && urls.size() == 1) {
            singleURL.setVisibility(View.VISIBLE);
            openUrl.setVisibility(View.GONE);
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(urls.get(0));
            sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            singleURL.setText(sb);
            singleURL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                    launchURL(listSelectedItem.getMID(), urls.get(0));
                }
            });
        } else if (urls != null && urls.size() > 0) {
            singleURL.setVisibility(View.GONE);
            openUrl.setVisibility(View.VISIBLE);
            openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (position != 0) {
                        alertDialog.dismiss();
                        launchURL(listSelectedItem.getMID(), urls.get(position));
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            urls.add(0, activity.getString(R.string.ClickToSelectURL));
            openUrl.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return urls.size();
                }

                @Override
                public Object getItem(int position) {
                    return position;
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1,
                            null);
                    TextView textView = (TextView) rowView.findViewById(android.R.id.text1);
                    textView.setSingleLine(false);
                    textView.setMaxLines(5);
                    SpannableStringBuilder sb = new SpannableStringBuilder();
                    sb.append(urls.get(position));
                    if (position == 0) {
                        textView.setTextColor(0xFF808080);
                    } else {
                        sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    textView.setText(sb);
                    return rowView;
                }
            });
        } else {
            openUrl.setVisibility(View.GONE);
            singleURL.setVisibility(View.GONE);
        }
        final String UName = listSelectedItem.User.UName;
        View recommendMessage = dialogView.findViewById(R.id.recommend_message);
        View deleteMessage = dialogView.findViewById(R.id.delete_message);
        View saveMessage = dialogView.findViewById(R.id.save_message);
        View unsaveMessage = dialogView.findViewById(R.id.unsave_message);
        //View subscribeUser = dialogView.findViewById(R.id.subscribe_user);
        View subscribeMessage = dialogView.findViewById(R.id.subscribe_message);
        //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user);
        View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message);
        View translateMessage = dialogView.findViewById(R.id.translate_message);
        View shareMessage = dialogView.findViewById(R.id.share_message);
        //View blacklistUser = dialogView.findViewById(R.id.blacklist_user);
        //View filterUser = dialogView.findViewById(R.id.filter_user);
        //View userBlog = dialogView.findViewById(R.id.user_blog);
        //View userStats = dialogView.findViewById(R.id.user_stats);
        View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser);
        Button userCenter = (Button) dialogView.findViewById(R.id.user_center);
        if (null == dialogView.findViewById(R.id.column_3)) {
            // only for portrait
            userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText());
        }

        unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        subscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        unsaveMessage.setEnabled(listSelectedItem.getRID() == 0);
        recommendMessage.setEnabled(listSelectedItem.getRID() == 0);

        if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) {
            recommendMessage.setVisibility(View.GONE);
        } else {
            deleteMessage.setVisibility(View.GONE);
        }
        if (messagesSource instanceof SavedMessagesSource) {
            saveMessage.setVisibility(View.GONE);
        } else {
            unsaveMessage.setVisibility(View.GONE);
        }
        recommendMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionRecommendMessage();
            }
        });
        deleteMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionDeleteMessage();
            }
        });
        saveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSaveMessage();
            }
        });
        unsaveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsaveMessage();
            }
        });
        //            subscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionSubscribeUser();
        //                }
        //            });
        subscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSubscribeMessage();
            }
        });
        //            unsubscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUnsubscribeUser();
        //                }
        //            });
        unsubscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsubscribeMessage();
            }
        });
        translateMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionTranslateMessage();
            }
        });
        shareMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionShareMessage();
            }
        });
        //            blacklistUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionBlacklistUser();
        //                }
        //            });
        //            filterUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionFilterUser(UName);
        //                }
        //            });
        //            userBlog.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserBlog();
        //                }
        //            });
        //            userStats.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserStats();
        //                }
        //            });
        openMessageInBrowser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionOpenMessageInBrowser();
            }
        });
        userCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUserCenter();
            }
        });
        completeInitDialogMode(alertDialog, dialogView);
        alertDialog.show();
    }
}

From source file:android.support.v7.app.WindowDecorActionBar.java

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {//ww  w. j  av a  2  s  .c om
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:org.catnut.fragment.TweetFragment.java

/**
 * ??/* www . j av  a  2 s.c  o m*/
 *
 * @param thumb url
 * @param originalUrl url
 */
private void loadThumbs(String thumb, final String originalUrl, final ImageView thumbs,
        final JSONArray jsonArray, View overflow) {
    if (!TextUtils.isEmpty(thumb)) {
        if (mStayInLatest) {
            int screenWidth = CatnutUtils.getScreenWidth(getActivity());
            Picasso.with(getActivity()).load(thumb).into(thumbs);
            thumbs.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return CatnutUtils.imageOverlay(v, event);
                }
            });
            thumbs.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    thumbs.getDrawable().clearColorFilter();
                    mText.invalidate();
                    Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                            SingleFragmentActivity.PHOTO_VIEWER);
                    intent.putExtra(Constants.PIC, originalUrl);
                    startActivity(intent);
                }
            });
        } else {
            thumbs.setImageResource(R.drawable.error);
        }
        thumbs.setVisibility(View.VISIBLE);
    } else {
        thumbs.setVisibility(View.GONE);
        overflow.setVisibility(View.GONE);
    }
    if (jsonArray != null && jsonArray.length() > 1) {
        overflow.setVisibility(View.VISIBLE);
        overflow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.tweet_pics, null);
                LinePageIndicator indicator = (LinePageIndicator) view.findViewById(R.id.indicator);
                final ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
                pager.setPageTransformer(true, new PageTransformer.DepthPageTransformer());
                pager.setAdapter(new PagerAdapter() {
                    @Override
                    public int getCount() {
                        return jsonArray.length();
                    }

                    @Override
                    public boolean isViewFromObject(View view, Object object) {
                        return view == object;
                    }

                    @Override
                    public void destroyItem(ViewGroup container, int position, Object object) {
                        container.removeView((View) object);
                    }

                    @Override
                    public Object instantiateItem(ViewGroup container, int position) {
                        View v = LayoutInflater.from(getActivity()).inflate(R.layout.photo, null);
                        TouchImageView iv = (TouchImageView) v.findViewById(R.id.image);
                        String url = jsonArray.optJSONObject(position).optString(Status.thumbnail_pic);
                        String replace = url.replace(Constants.THUMBNAIL, Status.MEDIUM_THUMBNAIL);
                        Picasso.with(getActivity()).load(replace).into(iv);
                        container.addView(v);
                        return v;
                    }
                });
                indicator.setViewPager(pager);
                new AlertDialog.Builder(
                        new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Dialog)).setView(view)
                                .setPositiveButton(getString(R.string.original_pics),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                ArrayList<Uri> urls = new ArrayList<Uri>(jsonArray.length());
                                                for (int i = 0; i < jsonArray.length(); i++) {
                                                    String s = jsonArray.optJSONObject(i)
                                                            .optString(Status.thumbnail_pic)
                                                            .replace(Constants.THUMBNAIL,
                                                                    Status.LARGE_THUMBNAIL);
                                                    urls.add(Uri.parse(s));
                                                }
                                                Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                                                        SingleFragmentActivity.GALLERY);
                                                intent.putExtra(GalleryPagerFragment.CUR_INDEX,
                                                        pager.getCurrentItem());
                                                intent.putExtra(GalleryPagerFragment.URLS, urls);
                                                intent.putExtra(GalleryPagerFragment.TITLE,
                                                        getString(R.string.tweet_pics));
                                                startActivity(intent);
                                            }
                                        })
                                .setNegativeButton(getString(R.string.close), null).show();
            }
        });
    } else {
        overflow.setVisibility(View.GONE);
    }
}

From source file:info.staticfree.android.units.Units.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ABOUT: {
        final Builder builder = new AlertDialog.Builder(this);

        builder.setTitle(R.string.dialog_about_title);
        builder.setIcon(R.drawable.icon);

        try {/*from   w w w.j a v a 2 s.  com*/
            final WebView wv = new WebView(this);
            final InputStream is = getAssets().open("README.xhtml");
            wv.loadDataWithBaseURL("file:///android_asset/", inputStreamToString(is), "application/xhtml+xml",
                    "utf-8", null);
            wv.setBackgroundColor(0);
            builder.setView(wv);
        } catch (final IOException e) {
            builder.setMessage(R.string.err_no_load_about);
            e.printStackTrace();
        }

        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                setResult(RESULT_OK);
            }
        });
        return builder.create();
    }

    case DIALOG_ALL_UNITS: {
        final Builder b = new Builder(Units.this);
        b.setTitle(R.string.dialog_all_units_title);
        final ExpandableListView unitExpandList = new ExpandableListView(Units.this);
        unitExpandList.setId(android.R.id.list);
        final String[] groupProjection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        // any selection below will select from the grouping description
        final Cursor cursor = managedQuery(UsageEntry.CONTENT_URI_CONFORM_TOP, groupProjection, null, null,
                UnitUsageDBHelper.USAGE_SORT);

        unitExpandList.setAdapter(new UnitsExpandableListAdapter(cursor, this,
                android.R.layout.simple_expandable_list_item_1, android.R.layout.simple_expandable_list_item_1,
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 },
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 }));
        unitExpandList.setCacheColorHint(0);
        unitExpandList.setOnChildClickListener(allUnitChildClickListener);
        b.setView(unitExpandList);
        return b.create();
    }

    case DIALOG_UNIT_CATEGORY: {
        final Builder b = new Builder(new ContextThemeWrapper(this, android.R.style.Theme_Black));
        final String[] from = { UsageEntry._UNIT };
        final int[] to = { android.R.id.text1 };
        b.setTitle("all units");
        final String[] projection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        final Cursor c = managedQuery(UsageEntry.CONTENT_URI, projection, null, null,
                UnitUsageDBHelper.USAGE_SORT);
        dialogUnitCategoryList = new SimpleCursorAdapter(this, android.R.layout.select_dialog_item, c, from,
                to);
        b.setAdapter(dialogUnitCategoryList, dialogUnitCategoryOnClickListener);

        return b.create();
    }

    case DIALOG_LOADING_UNITS: {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setIndeterminate(true);
        pd.setTitle(R.string.app_name);
        pd.setMessage(getText(R.string.dialog_loading_units));
        return pd;
    }

    default:
        throw new IllegalArgumentException("Unknown dialog ID:" + id);
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

public CustomSearchView getSearchView(boolean createIfNull) {
    if (searchView == null && createIfNull) {
        searchView = new CustomSearchView(
                C.API_LOLLIPOP ? new ContextThemeWrapper(this, R.style.Theme_Special_White)
                        : getActionBar().getThemedContext());
        searchView.setOnQueryTextListener(new CustomSearchView.OnQueryTextListener() {
            @Override/*from w  w  w . j a va  2 s. c  o  m*/
            public boolean onQueryTextSubmit(String query) {
                return page != null && page.onSearchSubmit(query);
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (page != null) {
                    page.onSearchQueryChange(newText);
                }
                return true;
            }
        });
    }
    return searchView;
}