Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

In this page you can find the example usage for android.content Intent setClassName.

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it//w ww. j a  v  a2s. com
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id"));
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = addItemToList(Main.default_study_list_id,
                            (String) item.item_node.atts.get("id"), ItemActivity.this);
                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default list

                        ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id,
                                (String) item.item_node.atts.get("id"), Main.default_study_list_id,
                                ItemActivity.this);
                        result = ItemActivity.add_sentence_list_result;
                        if (ItemActivity.add_sentence_list_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.item_node.atts.get("id"),
                                    Main.default_study_list_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this,
                                                item.item_node.atts.get("id").toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.repeater_list);

    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);

    lv = (ListView) findViewById(R.id.repeaterListView);
    tvAddress = (TextView) findViewById(R.id.tvAddress);

    xlocation = new Repeater("", LAT_DEFAULT, LNG_DEFAULT);

    rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this);
    xlocation.calcDistanceAll(rl);/*from   ww  w  . j av  a2  s  .  com*/
    rl.sort();

    adapter = new RepeaterAdapter(this, rl, xlocation, local_distance, excludeLink, excludeDirection);

    lv.setFastScrollEnabled(true);
    lv.setVerticalFadingEdgeEnabled(false);
    lv.setVerticalScrollBarEnabled(true);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(this);

    // SharedPreferences prefs = getSharedPreferences("Location",
    // MODE_PRIVATE);
    SharedPreferences prefshare = PreferenceManager.getDefaultSharedPreferences(this);
    int walkcount = prefshare.getInt("walkthrough", WALK_VERSION_CODE);
    if (walkcount < (WALK_VERSION_CODE + 1)) {
        Intent intent = new Intent();

        intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.SettingsActivity");
        startActivity(intent);

        intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.WalkthroughActivity");
        SharedPreferences.Editor prefEditor = prefshare.edit();
        walkcount++;

        SharedPreferences repeater_prefs = PreferenceManager.getDefaultSharedPreferences(this);

        m_deviceid = repeater_prefs.getString("deviceid", this.generateCallsign());
        prefEditor.putInt("walkthrough", walkcount);
        // prefEditor.putString("callsign", new
        // StringBuilder("9W2-").append(this.generateCallsign()).toString());
        prefEditor.putString("deviceid", m_deviceid);
        prefEditor.commit();

        startActivity(intent);

    }

    // need to put token to avoid app from popping up annoying select manual
    // dialog will be triggered if location/gps is not enabled AND if the
    // date in dd/MM is not equal to 'token' saved in StaticLocationActivity
    // location dialog
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM", Locale.US);
    Date date = new Date();

    SharedPreferences preftoken = getSharedPreferences("Location", MODE_PRIVATE);

    if (!this.isLocationEnabled(this)
            && !dateFormat.format(date).equalsIgnoreCase(preftoken.getString("token", "28/10"))) {

        // show dialog if Location Services is not enabled
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.gps_not_found_title); // GPS not found
        builder.setMessage(R.string.gps_not_found_message); // Want to
        // enable?

        // if yes - bring user to enable Location Service settings
        builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {

                Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                getApplicationContext().startActivity(intent);
            }
        });

        // if no - bring user to selecting Static Location Activity
        builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setClassName(getApplicationContext(),
                        "net.mypapit.mobile.myrepeater.StaticLocationActivity");
                startActivity(intent);

            }

        });
        builder.create().show();

    }

    new GPSThread(this).start();

    lv.setAdapter(adapter);

}

From source file:com.aware.Aware.java

/**
 * Starts a plugin. Expects the package name of the plugin.<br/>
 * It checks if the plugin does exist on the phone. If it doesn't, it will request the user to install it automatically.
 * @param context/* ww w  .j a v a2  s . c  o m*/
 * @param package_name
 */
public static void startPlugin(Context context, String package_name) {
    //Check if plugin is installed. If not, ask user to download it.
    Cursor is_installed = context.getContentResolver().query(Aware_Plugins.CONTENT_URI, null,
            Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null, null);
    if (is_installed != null && is_installed.moveToFirst()) {
        //We might just have it cached, but not installed
        if (isClassAvailable(context, package_name, "Plugin")) {
            //it's installed, start it!
            Intent plugin = new Intent();
            plugin.setClassName(package_name, package_name + ".Plugin");
            context.startService(plugin);
            if (Aware.DEBUG)
                Log.d(TAG, package_name + " started...");

            ContentValues rowData = new ContentValues();
            rowData.put(Aware_Plugins.PLUGIN_STATUS, Aware_Plugin.STATUS_PLUGIN_ON);
            context.getContentResolver().update(Aware_Plugins.CONTENT_URI, rowData,
                    Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null);
            is_installed.close();
            return;
        }
        is_installed.close();
    }

    HttpResponse response = new Https(awareContext)
            .dataGET("https://api.awareframework.com/index.php/plugins/get_plugin/" + package_name);
    if (response != null && response.getStatusLine().getStatusCode() == 200) {
        try {
            String data = EntityUtils.toString(response.getEntity());
            if (data.equals("[]"))
                return;

            JSONObject json_package = new JSONObject(data);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setSmallIcon(R.drawable.ic_stat_aware_plugin_dependency);
            mBuilder.setContentTitle("AWARE");
            mBuilder.setContentText("Plugin missing: " + json_package.getString("title") + ". Tap to install.");
            mBuilder.setDefaults(Notification.DEFAULT_ALL);
            mBuilder.setAutoCancel(true);

            Intent pluginIntent = new Intent(context, DownloadPluginService.class);
            pluginIntent.putExtra("package_name", package_name);
            pluginIntent.putExtra("is_update", false);

            PendingIntent clickIntent = PendingIntent.getService(context, 0, pluginIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(clickIntent);
            NotificationManager notManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notManager.notify(json_package.getInt("id"), mBuilder.build());

        } catch (ParseException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.sdk.download.providers.downloads.DownloadNotification.java

private void updateCompletedNotification(Collection<DownloadInfo> downloads) {
    for (DownloadInfo download : downloads) {
        if (!isCompleteAndVisible(download)) {
            continue;
        }/*from  ww w.  jav a2 s  .  c o m*/
        // Add the notifications
        Notification n = new Notification();
        n.icon = android.R.drawable.stat_sys_download_done;
        n.flags |= Notification.FLAG_AUTO_CANCEL;
        long id = download.mId;
        String title = download.mTitle;
        if (title == null || title.length() == 0) {
            title = mContext.getResources().getString(R.string.zuimeia_sdk_download_download_unknown_title);
        }
        Uri contentUri = ContentUris.withAppendedId(Downloads.getAllDownloadsContentURI(mContext), id);
        String caption;
        Intent intent;
        if (Downloads.isStatusError(download.mStatus)) {
            caption = mContext.getResources()
                    .getString(R.string.zuimeia_sdk_download_notification_download_failed);
            intent = new Intent(Constants.ACTION_LIST);
        } else {
            caption = mContext.getResources()
                    .getString(R.string.zuimeia_sdk_download_notification_download_complete);
            if (download.mDestination == Downloads.DESTINATION_EXTERNAL) {
                intent = new Intent(Constants.ACTION_OPEN);
            } else {
                intent = new Intent(Constants.ACTION_LIST);
            }
        }
        intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName());
        intent.setData(contentUri);

        n.when = download.mLastMod;
        n.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(mContext, 0, intent, 0));

        intent = new Intent(Constants.ACTION_HIDE);
        intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName());
        intent.setData(contentUri);
        // n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent,
        // 0); //notification??
        mSystemFacade.postNotification(download.mId, n);
    }
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static void showAlertNotification(String aImageUrl, String aAlertTitle, String aAlertText,
        String aAlertCookie, String aAlertName) {
    Log.i(LOGTAG,//from   ww w . j a  v  a  2  s.  c o m
            "GeckoAppShell.showAlertNotification\n" + "- image = '" + aImageUrl + "'\n" + "- title = '"
                    + aAlertTitle + "'\n" + "- text = '" + aAlertText + "'\n" + "- cookie = '" + aAlertCookie
                    + "'\n" + "- name = '" + aAlertName + "'");

    int icon = R.drawable.icon; // Just use the app icon by default

    Uri imageUri = Uri.parse(aImageUrl);
    String scheme = imageUri.getScheme();
    if ("drawable".equals(scheme)) {
        String resource = imageUri.getSchemeSpecificPart();
        resource = resource.substring(resource.lastIndexOf('/') + 1);
        try {
            Class<R.drawable> drawableClass = R.drawable.class;
            Field f = drawableClass.getField(resource);
            icon = f.getInt(null);
        } catch (Exception e) {
        } // just means the resource doesn't exist
        imageUri = null;
    }

    int notificationID = aAlertName.hashCode();

    // Remove the old notification with the same ID, if any
    removeNotification(notificationID);

    AlertNotification notification = new AlertNotification(GeckoApp.mAppContext, notificationID, icon,
            aAlertTitle, aAlertText, System.currentTimeMillis());

    // The intent to launch when the user clicks the expanded notification
    Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLICK);
    notificationIntent.setClassName(GeckoApp.mAppContext,
            GeckoApp.mAppContext.getPackageName() + ".NotificationHandler");

    // Put the strings into the intent as an URI "alert:<name>#<cookie>"
    Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie);
    notificationIntent.setData(dataUri);

    PendingIntent contentIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, notificationIntent, 0);
    notification.setLatestEventInfo(GeckoApp.mAppContext, aAlertTitle, aAlertText, contentIntent);
    notification.setCustomIcon(imageUri);
    // The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button
    Intent clearNotificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLEAR);
    clearNotificationIntent.setClassName(GeckoApp.mAppContext,
            GeckoApp.mAppContext.getPackageName() + ".NotificationHandler");
    clearNotificationIntent.setData(dataUri);
    notification.deleteIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);

    mAlertNotifications.put(notificationID, notification);

    notification.show();

    Log.i(LOGTAG, "Created notification ID " + notificationID);
}

From source file:de.baumann.hhsmoodle.data_todo.Todo_Fragment.java

public void setTodoList() {

    if (isFABOpen) {
        closeFABMenu();/*from  w w  w  .  j  a v  a2s  . co  m*/
    }

    NotificationManager nMgr = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "todo_title", "todo_content", "todo_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);
            helper_main.switchIcon(getActivity(), todo_icon, "todo_icon", iv_icon);

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(getActivity(), "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(getActivity(), n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(getActivity())
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(getActivity())
                        .setColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) getActivity()
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_todoBY", "note_title");
    sharedPref.edit().putString("filter_todoBY", "note_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(getActivity(), Activity_todo.class, false);
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(todo_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), todo_title, todo_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), todo_title, todo_content, "", "", "", "");
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), todo_title, todo_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.aware.Aware.java

/**
 * Given a plugin's package name, fetch the context card for reuse.
 * @param context: application context//from w  w w. j a va  2 s  . co m
 * @param package_name: plugin's package name
 * @return View for reuse (instance of LinearLayout)
 */
public static View getContextCard(final Context context, final String package_name) {

    if (!isClassAvailable(context, package_name, "ContextCard")) {
        return null;
    }

    String ui_class = package_name + ".ContextCard";
    LinearLayout card = new LinearLayout(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    card.setLayoutParams(params);
    card.setOrientation(LinearLayout.VERTICAL);

    try {
        Context packageContext = context.createPackageContext(package_name,
                Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);

        Class<?> fragment_loader = packageContext.getClassLoader().loadClass(ui_class);
        Object fragment = fragment_loader.newInstance();
        Method[] allMethods = fragment_loader.getDeclaredMethods();
        Method m = null;
        for (Method mItem : allMethods) {
            String mName = mItem.getName();
            if (mName.contains("getContextCard")) {
                mItem.setAccessible(true);
                m = mItem;
                break;
            }
        }

        View ui = (View) m.invoke(fragment, packageContext);
        if (ui != null) {
            //Check if plugin has settings. If it does, tapping the card shows the settings
            if (isClassAvailable(context, package_name, "Settings")) {
                ui.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent open_settings = new Intent();
                        open_settings.setClassName(package_name, package_name + ".Settings");
                        open_settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(open_settings);
                    }
                });
            }

            //Set card look-n-feel
            ui.setBackgroundColor(Color.WHITE);
            ui.setPadding(20, 20, 20, 20);
            card.addView(ui);

            LinearLayout shadow = new LinearLayout(context);
            LayoutParams params_shadow = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            params_shadow.setMargins(0, 0, 0, 10);
            shadow.setBackgroundColor(context.getResources().getColor(R.color.card_shadow));
            shadow.setMinimumHeight(5);
            shadow.setLayoutParams(params_shadow);
            card.addView(shadow);

            return card;
        } else {
            return null;
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.charabia.SmsViewActivity.java

@Override
public void onResume() {
    super.onResume();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefPhoneNumber = prefs.getString(PreferencesActivity.PHONE_NUMBER, null);
    if (prefPhoneNumber == null || prefPhoneNumber.length() <= 0) {

        Intent intent;

        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.setClassName(this, PreferencesActivity.class.getName());
        startActivity(intent);//  w  w w . jav  a  2 s .  c o  m

        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.setClassName(this, WebViewActivity.class.getName());
        intent.setData(Uri.parse(WebViewActivity.getBaseUrl(this, "/help", "enter_phone_number.html")));
        startActivity(intent);

        //Attempt to retrieve old keys

        android.content.ContentResolver cr = getContentResolver();
        android.database.Cursor cursor = cr.query(Data.CONTENT_URI,
                new String[] { Data._ID, Tools.PHONE, Tools.KEY }, Data.MIMETYPE + "=?",
                new String[] { Tools.CONTENT_ITEM_TYPE }, null);
        while (cursor.moveToNext()) {
            try {
                tools.updateOrCreateContactKey(cursor.getString(cursor.getColumnIndex(Tools.PHONE)),
                        Base64.decode(cursor.getString(cursor.getColumnIndex(Tools.KEY)), Base64.DEFAULT),
                        false);

                cr.delete(ContentUris.withAppendedId(Data.CONTENT_URI,
                        cursor.getLong(cursor.getColumnIndex(Data._ID))), null, null);
            } catch (NoContactException e) {
                e.printStackTrace();
                Toast.makeText(this, "No contact for " + cursor.getColumnIndex(Tools.PHONE), Toast.LENGTH_SHORT)
                        .show();
            }

        }
    }
}

From source file:com.flipzu.flipzu.Recorder.java

private Void logoutRecorder() {
    /* track "Logout" */
    tracker.trackEvent("Recorder", "Click", "Logout", 0);

    SharedPreferences.Editor editor = settings.edit();
    editor.putString("username", null);
    editor.putString("token", null);
    editor.commit();/*from   w  w w.j a  va2s.c om*/
    Intent loginIntent = new Intent();
    loginIntent.setClassName("com.flipzu.flipzu", "com.flipzu.flipzu.Flipzu");
    startActivity(loginIntent);
    Recorder.this.finish();
    return null;
}

From source file:org.videolan.vlc.AudioService.java

private void updateWidget(Context context) {
    Log.d(TAG, "Updating widget");
    Intent i = new Intent();
    i.setClassName(WIDGET_PACKAGE, WIDGET_CLASS);
    i.setAction(ACTION_WIDGET_UPDATE);//from  www.  jav a  2  s .  co  m

    if (mCurrentMedia != null) {
        i.putExtra("title", mCurrentMedia.getTitle());
        i.putExtra("artist", mCurrentMedia.getArtist());
    } else {
        i.putExtra("title", "VLC mini player");
        i.putExtra("artist", "");
    }
    i.putExtra("isplaying", mLibVLC.isPlaying());

    Bitmap cover = mCurrentMedia != null ? AudioUtil.getCover(this, mCurrentMedia, 64) : null;
    i.putExtra("cover", cover);

    sendBroadcast(i);
}