Example usage for android.content.res Resources getIdentifier

List of usage examples for android.content.res Resources getIdentifier

Introduction

In this page you can find the example usage for android.content.res Resources getIdentifier.

Prototype

public int getIdentifier(String name, String defType, String defPackage) 

Source Link

Document

Return a resource identifier for the given resource name.

Usage

From source file:com.cem.echo.Echo.java

protected boolean getCertificateList(CallbackContext callbackContext) {
    System.out.println("-----getcertlist: entrance deneme");

    List<String> certs = new ArrayList<String>();

    try {//from   www . jav a  2  s. c om
        /*            InputStream lisansStream = cordova.getActivity().getResources().openRawResource(cordova.getActivity().getResources().getIdentifier("lisans", "raw", cordova.getActivity().getPackageName()));
                    LicenseUtil.setLicenseXml(lisansStream);
                    lisansStream.close();*/

        Resources activityRes = cordova.getActivity().getResources();
        int lisansid = activityRes.getIdentifier("lisans", "raw", cordova.getActivity().getPackageName());
        InputStream lisansStream = activityRes.openRawResource(lisansid);
        LicenseUtil.setLicenseXml(lisansStream);
        lisansStream.close();

        System.out.println("-----getcertlist: lisans aldik");

        mTerminalHandler = new SCDTerminalHandler(cordova.getActivity());

        mAPDUSmartCard = new APDUSmartCard(mTerminalHandler);
        mAPDUSmartCard.setDisableSecureMessaging(true);

        CardTerminal[] terminalList = mAPDUSmartCard.getTerminalList();

        CardTerminal cardTerminal = terminalList[0];

        //System.out.println("hehehe " + terminalList[0]);

        mAPDUSmartCard.openSession(cardTerminal);
        String readerName = cardTerminal.getName();
        List<byte[]> signCertValueList = mAPDUSmartCard.getSignatureCertificates();

        certificateList = new ArrayList<ECertificate>();

        for (byte[] signCertValue : signCertValueList) {
            ECertificate signCert = new ECertificate(signCertValue);
            //Sadece nitelikli sertifikalar ekiliyor.
            //Kanuni geerlilii olmayan sertifikalarla imza atlmak istenirse bu kontrol kaldrlabilir.
            //  if(signCert.isQualifiedCertificate()){
            certificateList.add(signCert);
            System.out.println("Sertifika Sahibi :" + signCert.getSubject().getCommonNameAttribute());
            certs.add(signCert.getSubject().getCommonNameAttribute());
            //}
        }
    } catch (Exception e) {
        e.printStackTrace();
        PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        //callbackContext.error("Sertifikalar alrken bir hata olutu.");
        return false;
    }

    String[] res = new String[certs.size()];
    certs.toArray(res);

    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, new JSONArray(certs));
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
    //callbackContext.success(new JSONArray(certs));
    return true;
}

From source file:arun.com.chromer.browsing.customtabs.dynamictoolbar.AppColorExtractorJob.java

private boolean extractColorFromResources(@NonNull final String packageName) {
    try {/*w  ww.  j  ava2s  . c om*/
        int color;
        final Resources resources = getPackageManager().getResourcesForApplication(packageName);
        // Try to extract appcompat primary color value
        int appCompatId = resources.getIdentifier("colorPrimary", "attr", packageName);
        if (appCompatId > 0) {
            // Successful, let's get the themed value of this attribute
            color = getThemedColor(resources, appCompatId, packageName);
            if (color != NO_COLOR) {
                saveColorToDb(packageName, color);
                return true;
            }
        }
        // If above was not successful, then attempt to get lollipop colorPrimary attribute
        int lollipopAttrId = resources.getIdentifier("android:colorPrimary", "attr", packageName);
        if (lollipopAttrId > 0) {
            // Found
            color = getThemedColor(resources, lollipopAttrId, packageName);
            if (color != NO_COLOR) {
                saveColorToDb(packageName, color);
                return true;
            }
        }
        return false;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.sherdle.universal.ConfigParser.java

public int getDrawableByName(String name) {
    Resources resources = context.getResources();
    final int resourceId = resources.getIdentifier(name, "drawable", context.getPackageName());
    return resourceId;
}

From source file:com.lox.xtendedwallz.Wallpaper.java

private void fetchWallpapers(Resources resources, String packageName, int list) {
    final String[] extras = resources.getStringArray(list);
    for (String extra : extras) {
        int res = resources.getIdentifier(extra, "drawable", packageName);
        if (res != 0) {
            sWallpapers.add(res);/*from www. j av  a2 s  .c o  m*/
        }
    }
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

/**
 * ??//from  ww  w .ja v a2  s  . c  o m
 * @return
 */
private boolean checkDeviceHasNavigationBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        display.getRealMetrics(realDisplayMetrics);
        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getMetrics(displayMetrics);
        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;
        return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
    } else {
        boolean hasNavigationBar = false;
        Resources resources = getContext().getResources();
        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            hasNavigationBar = resources.getBoolean(id);
        }
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method m = systemPropertiesClass.getMethod("get", String.class);
            String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
            if ("1".equals(navBarOverride)) {
                hasNavigationBar = false;
            } else if ("0".equals(navBarOverride)) {
                hasNavigationBar = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return hasNavigationBar;
    }
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private int getStatusBarHeight() {
    int result = 0;
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId);
    }//  w ww.  ja v  a2s  .co m
    return result;
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private int getNavigationBarHeight() {
    int result = 0;
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId);
    }//w ww. j a v  a  2s  .c  o m
    return result;
}

From source file:com.linangran.tgfcapp.activities.MainActivity.java

public int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }//from w ww . j  a  va 2s.com
    return 0;
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void oldPushNotification(Context context, Intent intent) {
    PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground);
    if (EBrowserActivity.isForground) {
        if (mContext != null) {
            intent.putExtra("ntype", F_TYPE_PUSH);
            ((EBrowserActivity) mContext).handleIntent(intent);
        }//from  ww  w  .java2  s  . c  o m
    } else {
        CharSequence tickerText = intent.getStringExtra("title"); // ????
        Resources res = context.getResources();
        int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
        long when = System.currentTimeMillis(); // ?
        // ??Nofification

        String notifyTitle = null;
        String pushMessage = intent.getStringExtra("message");
        String value = intent.getStringExtra("data"); // ??json
        try {
            JSONObject bodyJson = new JSONObject(value);
            notifyTitle = bodyJson.getString("msgName");// ?
        } catch (Exception e) {
            PushReportUtility.oe("onReceive", e);
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName?
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = "APPCAN";// widgetNameAPPCAN?
        }
        CharSequence contentTitle = notifyTitle; // ?
        Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity
        notificationIntent.putExtra("data", value);
        notificationIntent.putExtra("message", pushMessage);
        notificationIntent.putExtra("ntype", F_TYPE_PUSH);
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        Notification notification = new Notification(icon, tickerText, when);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        if (Build.VERSION.SDK_INT >= 16) {
            try {
                Field priorityField = Notification.class.getField("priority");
                priorityField.setAccessible(true);
                priorityField.set(notification, 1);
            } catch (Exception e) {
                PushReportUtility.oe("onReceive", e);
            }
        }
        PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent);
        // NotificationNotificationManager
        mNotificationManager.notify(notificationNB, notification);
        notificationNB++;
    }
}

From source file:net.kjmaster.cookiemom.global.CookieActionActivity.java

private View getDoneButton() {
    Resources resources = Resources.getSystem();
    if (resources == null) {
        return null;
    }//from w w w  .  j  a  v  a 2s .  co  m
    int doneButtonId = resources.getIdentifier("action_mode_close_button", "id", "android");
    return this.findViewById(doneButtonId);
}