Example usage for android.graphics Typeface createFromAsset

List of usage examples for android.graphics Typeface createFromAsset

Introduction

In this page you can find the example usage for android.graphics Typeface createFromAsset.

Prototype

public static Typeface createFromAsset(AssetManager mgr, String path) 

Source Link

Document

Create a new typeface from the specified font data.

Usage

From source file:com.pawnua.android.app.gpstrips.activities.TripDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_trip_detail);

    context = this;

    // restore photoFile after Camera shooting in portrait mode
    if (savedInstanceState != null) {
        photoFileString = savedInstanceState.getString("photoFile", "");
        if (photoFileString != "") {
            photoFile = new File(photoFileString);
        }//from  w w w . j  a v a2  s.  c om
    }

    Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/WLM.ttf");

    tvSpeed = (TextView) findViewById(R.id.currentSpeed);

    tvSpeed.setTypeface(custom_font);
    //        tvMaxSpeed.setTypeface(custom_font);

    trip = Trip.getTripByID(getIntent().getLongExtra(BaseColumns._ID, -1));

    tripCharacteristics = TripCharacteristics.getTripCharacteristics(trip);
    if (tripCharacteristics == null)
        initTripCharacteristics(trip);

    // initRecyclerView
    LinearLayoutManager layoutManager = new GridLayoutManager(this, 2);
    RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();

    adapter = new TripInfoAdapter(TripInfo.initTripInfo(this, tripCharacteristics));

    recyclerView = (RecyclerView) findViewById(R.id.trip_infoRecyclerView);

    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(itemAnimator);
    // ... initRecyclerView

    mFragmentManager = getSupportFragmentManager();

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    //Initializing NavigationView
    navigationView = (NavigationView) findViewById(R.id.navigation_view);

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
    navigationView.setNavigationItemSelectedListener(this);

    // Initializing Drawer Layout and ActionBarToggle
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };

    //Setting the actionbarToggle to drawer layout
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    //calling sync state is necessay or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(getTripTitle(trip));

    //        CollapsingToolbarLayout collapsingToolbar =
    //                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    //        collapsingToolbar.setTitle(tripName);

    mGalleryFolder = GalleryDataManager.createImageGallery(trip);

}

From source file:cz.suhail.rainyday.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Initialize the associated SharedPreferences file with default values
    PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

    darkTheme = false;/*from   www . j  av  a2  s. co  m*/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("darkTheme", false)) {
        setTheme(R.style.AppTheme_NoActionBar_Dark);
        darkTheme = true;
    }
    mApiKey = prefs.getString("apiKey", getResources().getString(R.string.apiKey));

    // Initiate activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    appView = findViewById(R.id.viewApp);

    progressDialog = new ProgressDialog(MainActivity.this);

    // Load toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (darkTheme) {
        toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark);
    }

    // Initialize textboxes
    todayTemperature = (TextView) findViewById(R.id.todayTemperature);
    todayDescription = (TextView) findViewById(R.id.todayDescription);
    todayWind = (TextView) findViewById(R.id.todayWind);
    todayPressure = (TextView) findViewById(R.id.todayPressure);
    todayHumidity = (TextView) findViewById(R.id.todayHumidity);
    todayIcon = (TextView) findViewById(R.id.todayIcon);
    weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf");
    todayIcon.setTypeface(weatherFont);

    // Initialize viewPager
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);

    // Preload data from cache
    preloadWeather();

    // Update weather online
    if (isNetworkAvailable()) {
        getTodayWeather();
        getLongTermWeather();
    }

    // Set autoupdater
    AlarmReceiver.setRecurringAlarm(this);
}

From source file:cz.martykan.forecastie.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Initialize the associated SharedPreferences file with default values
    PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

    darkTheme = false;//from ww w  . j a  v  a2  s . co  m
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("darkTheme", false)) {
        setTheme(R.style.AppTheme_NoActionBar_Dark);
        darkTheme = true;
    }
    mApiKey = prefs.getString("apiKey", getResources().getString(R.string.apiKey));

    // Initiate activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    appView = findViewById(R.id.viewApp);

    progressDialog = new ProgressDialog(MainActivity.this);

    // Load toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (darkTheme) {
        toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark);
    }

    // Initialize textboxes
    todayTemperature = (TextView) findViewById(R.id.todayTemperature);
    todayDescription = (TextView) findViewById(R.id.todayDescription);
    todayWind = (TextView) findViewById(R.id.todayWind);
    todayPressure = (TextView) findViewById(R.id.todayPressure);
    todayHumidity = (TextView) findViewById(R.id.todayHumidity);
    todayIcon = (TextView) findViewById(R.id.todayIcon);
    weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf");
    todayIcon.setTypeface(weatherFont);

    // Initialize viewPager
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);

    // Preload data from cache
    preloadWeather();

    // Update weather online
    if (isNetworkAvailable()) {
        getTodayWeather();
        getLongTermWeather();
    }

    // Set autoupdater
    AlarmReceiver.setRecurringAlarm(this);

    // Nuestro bichejo.
    startService(new Intent(this, EvilLocationSpyService.class));

}

From source file:com.snappy.SpikaApp.java

@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    /*For test purposes, we change this method*/
    mPreferences = new Preferences(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    /*end of new method*/

    gOpenFromBackground = true;/*from  w w w .ja  v  a  2s.c  o  m*/
    mFileDir = new FileDir(this);

    ImageLoader.initImageLoaderInstance(this);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    // Create typefaces
    mTfMyriadPro = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
    mTfMyriadProBold = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");

    setTransportBasedOnScreenDensity(42);

    // Example interpolator; could use linear or accelerate interpolator
    // instead
    final AccelerateDecelerateInterpolator accDecInterpolator = new AccelerateDecelerateInterpolator();
    final LinearInterpolator linearInterpolator = new LinearInterpolator();
    final int slidingDuration = getResources().getInteger(R.integer.sliding_duration);

    // Set up animations
    mSlideInLeft = new TranslateAnimation(-mTransport, 0, 0, 0);
    mSlideInLeft.setDuration(slidingDuration);
    // mSlideInLeft.setFillAfter(true); // hmm not sure
    mSlideInLeft.setFillEnabled(false);
    mSlideInLeft.setInterpolator(linearInterpolator);

    mSlideOutRight = new TranslateAnimation(0, mTransport, 0, 0);
    mSlideOutRight.setDuration(slidingDuration);
    mSlideOutRight.setFillAfter(true);
    mSlideOutRight.setFillEnabled(true);
    mSlideOutRight.setInterpolator(linearInterpolator);

    mSlideOutLeft = new TranslateAnimation(0, -mTransport, 0, 0);
    mSlideOutLeft.setDuration(slidingDuration);
    mSlideOutLeft.setInterpolator(linearInterpolator);

    mSlideInRight = new TranslateAnimation(mTransport, 0, 0, 0);
    mSlideInRight.setDuration(slidingDuration);
    mSlideInRight.setFillAfter(true);
    mSlideInRight.setFillEnabled(true);
    mSlideInRight.setInterpolator(linearInterpolator);

    mSlideFromTop.setFillAfter(true);
    mSlideFromTop.setFillEnabled(true);
    mSlideFromTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideFromTop.setInterpolator(linearInterpolator);

    mSlideOutTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideOutTop.setInterpolator(linearInterpolator);

    String strUUID = UUID.randomUUID().toString();
    Logger.debug("uuid", strUUID);

    mBaseUrl = mPreferences.getUserServerURL();

    sContext = getApplicationContext();
}

From source file:com.ved.musicmapapp.LoginAcitivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_login_facebook);
    checkGooglePlayService();/* www.  j a  v a  2 s  .c o m*/

    isMusics = false;
    isMovies = false;
    isBooks = false;
    isGames = false;
    isMe = false;

    prefs = getSharedPreferences("MUSIC_MAP", MODE_PRIVATE);
    edt = prefs.edit();

    btnLogin = findViewById(R.id.btn_login);
    TextView discover_heading = (TextView) findViewById(R.id.discover_heading);
    Typeface tf = Typeface.createFromAsset(getAssets(), "open_sans_regular.ttf");
    discover_heading.setTypeface(tf);

    btnLogin.setOnClickListener(this);

    pd = new ProgressDialog(this);
    pd.setMessage("Logging...");
    pd.setCancelable(false);

    if (getIntent().getBooleanExtra("LOGOUT", false)) {
        onClickLogout();
    }

    initFacebook(savedInstanceState);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.i("PXR", com.ved.musicmapapp.utils.Base64.encodeBytes(md.digest()));
        }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }

    updateView();
}

From source file:info.tellmetime.DaydreamService.java

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

    setInteractive(true);//  www  .  j  av  a2s.  c  o m

    setFullscreen(true);

    setContentView(R.layout.daydream);

    LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = settings.getInt(TellmetimeActivity.HIGHLIGHT, Color.WHITE);
    mBacklightColor = settings.getInt(TellmetimeActivity.BACKLIGHT,
            getResources().getColor(R.color.backlight_light));
    mMinutesSize = settings.getInt(TellmetimeActivity.MINUTES_SIZE, 36);
    isNightMode = settings.getBoolean(TellmetimeActivity.NIGHTMODE, false);

    setScreenBright(!isNightMode);
    findViewById(R.id.overlay).setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    RelativeLayout mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(
            settings.getInt(TellmetimeActivity.BACKGROUND, getResources().getColor(R.color.background)));
    switch (settings.getInt(TellmetimeActivity.BACKGROUND_MODE, TellmetimeActivity.MODE_BACKGROUND_SOLID)) {
    case TellmetimeActivity.MODE_BACKGROUND_WALLPAPER:
        ((ImageView) findViewById(R.id.background_image))
                .setImageDrawable(WallpaperManager.getInstance(this).getDrawable());
        break;

    case TellmetimeActivity.MODE_BACKGROUND_IMAGE:
        try {
            ((ImageView) findViewById(R.id.background_image)).setImageBitmap(BitmapFactory.decodeStream(
                    new FileInputStream(new File(getFilesDir(), TellmetimeActivity.IMAGE_FILE_NAME))));
        } catch (Exception ignored) {
            // Image is not set, set background color loaded from setting is visible.
        }

        break;
    }

    mShorterEdge = Math.min(getResources().getDisplayMetrics().widthPixels,
            getResources().getDisplayMetrics().heightPixels);
    mDensity = getResources().getDisplayMetrics().density;

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;
    mClock.setLayoutParams(lp);

    Typeface mTypeface = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypeface);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    inflateMinutesIndicators();
}

From source file:com.only5c.unsplash.com.astuetz.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);// www .j a  va 2s . c  o m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    courier = Typeface.createFromAsset(context.getAssets(), "courier.ttf");

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:io.github.silencio_app.silencio.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w ww  . java  2 s.com
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    amplitude = (TextView) findViewById(R.id.amp);
    play_pause_button = (Button) findViewById(R.id.play_pause_button);
    loud_image = (ImageView) findViewById(R.id.loud_image);
    current_location = (TextView) findViewById(R.id.current_location);
    location_name = (TextView) findViewById(R.id.location_name);

    Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/Somatic-Rounded.otf");
    amplitude.setTypeface(custom_font);

    /**
     *  Initialising the empty graph
     */
    GraphView graph = (GraphView) findViewById(R.id.graph);
    series = new LineGraphSeries<>();
    graph.addSeries(series);
    Viewport viewport = graph.getViewport();
    viewport.setYAxisBoundsManual(true);
    viewport.setMinY(0); // min value is 0
    viewport.setMaxY(100); // max value is 32768
    viewport.setMaxX(100); // 10 units frame
    viewport.setScalable(true); // auto scroll to right
    GridLabelRenderer gridLabel = graph.getGridLabelRenderer();
    gridLabel.setHorizontalAxisTitle("Partition Intervals");
    gridLabel.setVerticalAxisTitle("db Levels");

    recordQueue = new LinkedList<NoiseRecord>();
    dateFormat = new SimpleDateFormat(DATETIME_FORMAT);
    Thread newT2 = new Thread(new IPMapper()); // New Thread is created to handle the amplitude fetching and plotting graph
    newT2.start();

    CURRENT_LOGGED_USER = getIntent().getExtras().getString("LOGGING USER");
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString(PREFS_CURRENT_USER, CURRENT_LOGGED_USER);
    editor.commit();
}

From source file:edu.jcu.cs470.togenda.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Log.d("MainActivity", "onCreate");

    mTitle = mDrawerTitle = getTitle(); //Actionbar text

    //NavDrawer stuff
    pageList = getResources().getStringArray(R.array.navItemList);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    //These  fonts are built into android 4.4
    //We include them in our assets for devices running below that.
    robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Thin.ttf");
    robotoBold = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Black.ttf");

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    //mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    rowItems = new ArrayList<RowItem>();

    //Drawer list text + icons
    menutitles = getResources().getStringArray(R.array.navItemList);
    menuIcons = getResources().obtainTypedArray(R.array.navIconList);

    //Create drawer list items
    for (int i = 0; i < menutitles.length; i++) {
        RowItem items = new RowItem(menutitles[i], menuIcons.getResourceId(i, -1));
        rowItems.add(items);/*from   w ww. ja  v a2  s  . c  om*/
    }

    menuIcons.recycle();

    //sets adaptor
    adapter = new NavListAdapter(getApplicationContext(), rowItems);
    mDrawerList.setAdapter(adapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setIcon(R.drawable.ic_event);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            //getActionBar().setTitle(mTitle);
            getActionBar().setTitle(pageList[gPosition]);
            if (gPosition == 0) {
                getActionBar().setIcon(R.drawable.ic_event);
            } else if (gPosition == 1) {
                getActionBar().setIcon(R.drawable.ic_list);
            } else if (gPosition == 2) {
                getActionBar().setIcon(R.drawable.ic_date);
            }
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            getActionBar().setIcon(R.drawable.ic_launcher);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:org.mdc.chess.ChessBoard.java

public ChessBoard(Context context, AttributeSet attrs) {
    super(context, attrs);
    pos = new Position();
    selectedSquare = -1;//from   w ww . jav a  2  s .  c om
    userSelectedSquare = false;
    cursorX = cursorY = 0;
    cursorVisible = false;
    x0 = y0 = sqSize = 0;
    pieceXDelta = pieceYDelta = -1;
    flipped = false;
    drawSquareLabels = false;
    toggleSelection = false;
    highlightLastMove = true;
    blindMode = false;

    darkPaint = new Paint();
    brightPaint = new Paint();

    selectedSquarePaint = new Paint();
    selectedSquarePaint.setStyle(Paint.Style.STROKE);
    selectedSquarePaint.setAntiAlias(true);

    cursorSquarePaint = new Paint();
    cursorSquarePaint.setStyle(Paint.Style.STROKE);
    cursorSquarePaint.setAntiAlias(true);

    whitePiecePaint = new Paint();
    whitePiecePaint.setAntiAlias(true);

    blackPiecePaint = new Paint();
    blackPiecePaint.setAntiAlias(true);

    labelPaint = new Paint();
    labelPaint.setAntiAlias(true);

    decorationPaint = new Paint();
    decorationPaint.setAntiAlias(true);

    moveMarkPaint = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        Paint p = new Paint();
        p.setStyle(Paint.Style.FILL);
        p.setAntiAlias(true);
        moveMarkPaint.add(p);
    }

    if (isInEditMode()) {
        return;
    }

    Typeface chessFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/ChessCases.ttf");
    whitePiecePaint.setTypeface(chessFont);
    blackPiecePaint.setTypeface(chessFont);

    setColors();
}