Example usage for android.graphics Typeface NORMAL

List of usage examples for android.graphics Typeface NORMAL

Introduction

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

Prototype

int NORMAL

To view the source code for android.graphics Typeface NORMAL.

Click Source Link

Usage

From source file:com.stasbar.knowyourself.timer.CountingTimerView.java

public CountingTimerView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    Resources r = context.getResources();
    mDefaultColor = mWhiteColor = ContextCompat.getColor(context, R.color.colorPrimary);
    mPressedColor = mAccentColor = ContextCompat.getColor(context, R.color.colorPrimary);
    mBigFontSize = r.getDimension(R.dimen.big_font_size);
    mSmallFontSize = r.getDimension(R.dimen.small_font_size);

    mPaintBigThin.setAntiAlias(true);// ww  w  .  j  ava 2 s .c  o  m
    mPaintBigThin.setStyle(Paint.Style.STROKE);
    mPaintBigThin.setTextAlign(Paint.Align.CENTER);
    mPaintBigThin.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));

    mPaintMed.setAntiAlias(true);
    mPaintMed.setStyle(Paint.Style.STROKE);
    mPaintMed.setTextAlign(Paint.Align.CENTER);
    mPaintMed.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    resetTextSize();
    setTextColor(mDefaultColor);

    // allDigits will contain ten digits: "0123456789" in the default locale
    final String allDigits = String.format(Locale.getDefault(), "%010d", 123456789);
    mBigSeconds = new UnsignedTime(mPaintBigThin, 0.f, allDigits);
    mBigHours = new SignedTime(mBigSeconds, HOURS_MINUTES_SPACING);
    mBigMinutes = new SignedTime(mBigSeconds, HOURS_MINUTES_SPACING);
    mMedHundredths = new Hundredths(mPaintMed, HUNDREDTHS_SPACING, allDigits);

    mRadiusOffset = Utils.calculateRadiusOffset(r);
}

From source file:uk.co.ashtonbrsc.intentexplode.Explode.java

/** textViewToIgnore is not updated so current selected char in that textview will not change */
private void showAllIntentData(TextView textViewToIgnore) {
    showTextViewIntentData(textViewToIgnore);

    categoriesLayout.removeAllViews();/*  www  . j a  v  a 2  s  .  c om*/
    Set<String> categories = editableIntent.getCategories();
    StringBuilder stringBuilder = new StringBuilder();
    if (categories != null) {
        categoriesHeader.setVisibility(View.VISIBLE);
        stringBuilder.append(getResources().getString(R.string.categories));
        for (String category : categories) {
            stringBuilder.append(category).append(NEWLINE);
            TextView categoryTextView = new TextView(this);
            categoryTextView.setText(category);
            categoryTextView.setTextAppearance(this, R.style.TextFlags);
            categoriesLayout.addView(categoryTextView);
        }
    } else {
        categoriesHeader.setVisibility(View.GONE);
        // addTextToLayout("NONE", Typeface.NORMAL, categoriesLayout);
    }

    flagsLayout.removeAllViews();
    ArrayList<String> flagsStrings = getFlags();
    if (!flagsStrings.isEmpty()) {
        for (String thisFlagString : flagsStrings) {
            addTextToLayout(thisFlagString, Typeface.NORMAL, flagsLayout);
        }
    } else {
        addTextToLayout(getResources().getString(R.string.none), Typeface.NORMAL, flagsLayout);
    }

    extrasLayout.removeAllViews();
    try {
        Bundle intentBundle = editableIntent.getExtras();
        if (intentBundle != null) {
            Set<String> keySet = intentBundle.keySet();
            stringBuilder.append(getResources().getString(R.string.bundle_title_bold));
            int count = 0;

            for (String key : keySet) {
                count++;
                Object thisObject = intentBundle.get(key);
                addTextToLayout(getResources().getString(R.string.extra) + count, Typeface.BOLD, extrasLayout);
                String thisClass = thisObject.getClass().getName();
                if (thisClass != null) {
                    addTextToLayout(getResources().getString(R.string.class_text) + thisClass, Typeface.ITALIC,
                            STANDARD_INDENT_SIZE_IN_DIP, extrasLayout);
                }
                addTextToLayout(getResources().getString(R.string.key) + key, Typeface.ITALIC,
                        STANDARD_INDENT_SIZE_IN_DIP, extrasLayout);
                if (thisObject instanceof String || thisObject instanceof Long || thisObject instanceof Integer
                        || thisObject instanceof Boolean || thisObject instanceof Uri) {
                    addTextToLayout(getResources().getString(R.string.value) + thisObject.toString(),
                            Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP, extrasLayout);
                } else if (thisObject instanceof ArrayList) {
                    addTextToLayout(getResources().getString(R.string.values), Typeface.ITALIC, extrasLayout);
                    ArrayList thisArrayList = (ArrayList) thisObject;
                    for (Object thisArrayListObject : thisArrayList) {
                        addTextToLayout(thisArrayListObject.toString(), Typeface.ITALIC,
                                STANDARD_INDENT_SIZE_IN_DIP, extrasLayout);
                    }
                }
            }
        } else {
            addTextToLayout(getResources().getString(R.string.none), Typeface.NORMAL, extrasLayout);
        }
    } catch (Exception e) {
        // TODO Should make this red to highlight error
        addTextToLayout(getResources().getString(R.string.error_extracting_extras), Typeface.NORMAL,
                extrasLayout);
        e.printStackTrace();
    }

    // resolveInfo = pm.queryIntentServices(intent, 0);
    // stringBuilder.append("<br><b><u>" + resolveInfo.size()
    // + " services match this intent:</u></b><br>");
    // for (int i = 0; i < resolveInfo.size(); i++) {
    // ResolveInfo info = resolveInfo.get(i);
    // ActivityInfo activityinfo = info.activityInfo;
    // stringBuilder.append(activityinfo.packageName + "<br>");
    // }

    // intentDetailsHtml = stringBuilder.toString();
    // (((TextView) findViewById(R.id.text))).setText(intentDetailsHtml);
    refreshUI();
}

From source file:org.cocos2dx.lib.Cocos2dxBitmap.java

private static Paint newPaint(String fontName, int fontSize, int alignment) {
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);//from ww w  .java2s  .c o m
    paint.setTextSize(fontSize);
    paint.setAntiAlias(true);

    /*
     * Set type face for paint, now it support .ttf file.
     */
    if (fontName.endsWith(".ttf")) {
        try {
            //Typeface typeFace = Typeface.createFromAsset(context.getAssets(), fontName);
            Typeface typeFace = Cocos2dxTypefaces.get(context, fontName);
            paint.setTypeface(typeFace);
        } catch (Exception e) {
            Log.e("Cocos2dxBitmap", "error to create ttf type face: " + fontName);

            /*
             * The file may not find, use system font
             */
            paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
        }
    } else {
        paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
    }

    int hAlignment = alignment & 0x0F;
    switch (hAlignment) {
    case HALIGNCENTER:
        paint.setTextAlign(Align.CENTER);
        break;

    case HALIGNLEFT:
        paint.setTextAlign(Align.LEFT);
        break;

    case HALIGNRIGHT:
        paint.setTextAlign(Align.RIGHT);
        break;

    default:
        paint.setTextAlign(Align.LEFT);
        break;
    }

    return paint;
}

From source file:com.viewpagerindicator.TabTextPageIndicator.java

/**
 * textview/*from  w  w  w.j  a  v  a 2s  .  co m*/
 *
 * @param textView
 */
private void setTextColor(TextView textView) {
    if (textView == null) {
        return;
    }
    String textString = textView.getText().toString();
    if (textString.isEmpty()) {
        return;
    }
    int start = textString.indexOf("(");
    int end = textString.indexOf(")");
    if (start < 0 || end < 0 || end < start) {
        return;
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(textString);
    // ForegroundColorSpan ?BackgroundColorSpan
    ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.parseColor("#39a5ec"));
    builder.setSpan(redSpan, start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // ?
    builder.setSpan(new MyStyleSpan(Typeface.NORMAL), start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(builder);
}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Sets up the buttons and their listeners
 *//*w ww.j a va  2s  . c  o  m*/
private void setupButtons() {
    // populate favorites menu
    mMenuAdapter = new ArrayAdapter<MenuTuple>(this, android.R.layout.simple_spinner_item);

    try {
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        JSONObject conf = new JSONObject(settings.getString("stations", ""));
        JSONArray stations = conf.getJSONArray("stations");
        for (int i = 0; i < stations.length(); i++) {
            MenuTuple mt = MenuTuple.fromJSON(stations.getJSONObject(i));
            mMenuAdapter.add(mt);
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, "Failed to load station list");
    }

    // get references to buttons
    mFrequencyTextView = (TextView) findViewById(R.id.FrequencyTextView);
    mStationNameTextView = (TextView) findViewById(R.id.PSNTextView);
    mStationInfoTextView = (TextView) findViewById(R.id.RTTextView);
    mProgramTypeTextView = (TextView) findViewById(R.id.PTYTextView);
    final ImageButton scanUp = (ImageButton) findViewById(R.id.ScanUp);
    final ImageButton scanDown = (ImageButton) findViewById(R.id.ScanDown);
    final ImageButton pause = (ImageButton) findViewById(R.id.Pause);
    final ImageButton favorite = (ImageButton) findViewById(R.id.Favorite);
    mStationInfoTextView.setSelected(true);

    // set typeface for station frequency widget
    // this is done here instead of layout xml to keep ICS compatibility
    mFrequencyTextView.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    scanUp.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            scanUp.setEnabled(false);
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.changeFrequency(FmRadioService.SEEK_STEPUP, 0);
                }
            });
            return true;
        }
    });

    scanDown.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            scanDown.setEnabled(false);
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.changeFrequency(FmRadioService.SEEK_STEPDOWN, 0);
                }
            });
            return true;
        }
    });

    scanUp.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    if (mService.isStarted())
                        mService.changeFrequency(FmRadioService.SEEK_SCANUP, 0);
                }
            });
            scanUp.setEnabled(false);
        }
    });

    scanDown.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWorkerHandler.post(new Runnable() {
                public void run() {
                    mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    if (mService.isStarted())
                        mService.changeFrequency(FmRadioService.SEEK_SCANDOWN, 0);
                }
            });
            scanDown.setEnabled(false);
        }
    });

    pause.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mService.isStarted())
                mService.stopRadio();
            else {
                mWorkerHandler.post(new Runnable() {
                    public void run() {
                        mService.startRadio(mSelectedBand, mCurrentFrequency, mSelectedOutput);
                    }
                });
            }
        }
    });

    favorite.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            toggleFavorite(v, mCurrentFrequency);
        }
    });
}

From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java

@Override
public void create() {
    try {//www .  j a  v  a 2  s .  c o m
        setContentView(R.layout.news_feed_main);
        setTitle(R.string.news_feed);
        setTopbarTitleTypeface(Typeface.NORMAL);

        mainLayout = findViewById(R.id.news_feed_main_layout);
        listView = (RecyclerView) findViewById(R.id.news_feed_main_list);
        listView.setLayoutManager(new LinearLayoutManager(this));

        progressLayout = findViewById(R.id.news_feed_main_progress_layout);
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.news_feed_main_refresh);
        refreshLayout.setEnabled(false);

        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                loadRSS();
            }
        });

        currentIntent = getIntent();
        Bundle store = currentIntent.getExtras();
        widget = (Widget) store.getSerializable("Widget");

        if (widget == null) {
            handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100);
            return;
        }

        if (!TextUtils.isEmpty(widget.getTitle())) {
            setTopBarTitle(widget.getTitle());
        }

        setTopBarTitleColor(Color.parseColor("#000000"));

        setTopBarLeftButtonTextAndColor(getResources().getString(R.string.news_home_button),
                Color.parseColor("#000000"), true, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });

        try {
            if (widget.getPluginXmlData().length() == 0) {
                if (currentIntent.getStringExtra("WidgetFile").length() == 0) {
                    handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000);
                    return;
                }
            }
        } catch (Exception e) {
            handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000);
            return;
        }

        cachePath = widget.getCachePath() + "/feed-" + widget.getOrder();
        File cache = new File(this.cachePath);
        if (!cache.exists()) {
            cache.mkdirs();
        }

        // 3 seconds

        String widgetMD5 = Utils.md5(widget.getPluginXmlData());
        File cacheData = new File(cachePath + "/cache.data");
        if (cacheData.exists() && cacheData.length() > 0) {
            String cacheMD5 = readFileToString(cachePath + "/cache.md5").replace("\n", "");
            if (cacheMD5.equals(widgetMD5)) {
                useCache = true;
            } else {
                File[] files = cache.listFiles();
                for (File file : files) {
                    file.delete();
                }
                try {
                    BufferedWriter bw = new BufferedWriter(new FileWriter(new File(cachePath + "/cache.md5")));
                    bw.write(widgetMD5);
                    bw.close();
                    Log.d("IMAGES PLUGIN CACHE MD5", "SUCCESS");
                } catch (Exception e) {
                    Log.w("IMAGES PLUGIN CACHE MD5", e);
                }
            }
        }

        isOnline = NetworkUtils.isOnline(this);

        if (!isOnline && !useCache) {
            handler.sendEmptyMessage(NEED_INTERNET_CONNECTION);
            return;
        }

        new Thread() {
            @Override
            public void run() {
                timer = new Timer("EventsTimer", true);
                EntityParser parser;

                if (widget.getPluginXmlData().length() > 0) {
                    parser = new EntityParser(widget.getPluginXmlData());

                } else {
                    String xmlData = readXmlFromFile(currentIntent.getStringExtra("WidgetFile"));
                    parser = new EntityParser(xmlData);

                }

                parser.parse();

                Statics.color1 = parser.getColor1();
                Statics.color2 = parser.getColor2();
                Statics.color3 = parser.getColor3();
                Statics.color4 = parser.getColor4();
                Statics.color5 = parser.getColor5();

                handler.sendEmptyMessage(COLORS_RECEIVED);

                title = (widget.getTitle().length() > 0) ? widget.getTitle() : parser.getFuncName();
                items = parser.getItems();

                if ("rss".equals(parser.getFeedType())) {
                    Statics.isRSS = true;
                    AndroidSchedulers.mainThread().createWorker().schedule(new Action0() {
                        @Override
                        public void call() {
                            refreshLayout.setColorSchemeColors(Statics.color3);
                        }
                    });

                    feedURL = parser.getFeedUrl();
                    if (isOnline) {
                        FeedParser reader = new FeedParser(parser.getFeedUrl());
                        items = reader.parseFeed();

                        encoding = reader.getEncoding();

                        if (items.size() > 0) {
                            try {
                                ObjectOutputStream oos = new ObjectOutputStream(
                                        new FileOutputStream(cachePath + "/cache.data"));

                                oos.writeObject(items);
                                oos.flush();
                                oos.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                        }

                        Statics.isRSS = true;
                        AndroidSchedulers.mainThread().createWorker().schedule(new Action0() {
                            @Override
                            public void call() {
                                refreshLayout.setEnabled(true);
                            }
                        });
                    } else {
                        try {
                            ObjectInputStream ois = new ObjectInputStream(
                                    new FileInputStream(cachePath + "/cache.data"));
                            items = (ArrayList<FeedItem>) ois.readObject();
                            ois.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    Statics.isRSS = false;
                    AndroidSchedulers.mainThread().createWorker().schedule(new Action0() {
                        @Override
                        public void call() {
                            refreshLayout.setEnabled(false);
                        }
                    });
                }

                for (int i = 0; i < items.size(); i++) {
                    items.get(i).setTextColor(widget.getTextColor());
                    items.get(i).setDateFormat(widget.getDateFormat());
                }

                funcName = parser.getFuncName();
                selectShowType();
            }
        }.start();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:app.android.datetimepicker.date.SimpleMonthView.java

/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint./*from   ww  w. ja v a2 s  . c o  m*/
 */
protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mDayTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mMonthTitleBGPaint = new Paint();
    mMonthTitleBGPaint.setFakeBoldText(true);
    mMonthTitleBGPaint.setAntiAlias(true);
    mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
    mMonthTitleBGPaint.setTextAlign(Align.CENTER);
    mMonthTitleBGPaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mTodayNumberColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mDayTextColor);
    mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);

    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

public void setTypeface(final String typeface) {
    Typeface tempTypeface;//from   ww w.j a va2  s  . c om
    try {
        tempTypeface = Typeface.createFromAsset(getContext().getAssets(), typeface);
    } catch (Exception e) {
        tempTypeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
        e.printStackTrace();
    }

    setTypeface(tempTypeface);
}

From source file:com.sutromedia.android.core.PhotoActivity.java

public void onSetupView(View view, int viewId) {
    final IPhoto photo = getCurrentPhoto();
    if (photo != null) {

        int backgroundId = (viewId == R.layout.image_view_inside) ? R.drawable.attrib_inside
                : R.drawable.attrib_outside;

        Drawable background = getResources().getDrawable(backgroundId);
        background.setAlpha(155);//from   w  w  w.j  a v a  2 s .  com
        view.findViewById(R.image.licenseGroup).setBackgroundDrawable(background);
        setVisibility(view, R.image.caption, !mInSlideShow && !isSubsetOnEntry());
        TextView caption = (TextView) view.findViewById(R.image.caption);
        String entryName = photo.getEntryName();
        if (entryName != null) {
            entryName = entryName.replace(' ', '\u00A0');
            entryName += "\u00A0\u00A0\u25B6";
        }
        caption.setText(entryName);
        caption.setSingleLine(true);
        caption.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                onReceiveEntry(new NavigationDetailWeb(photo.getEntryId()));
            }
        });

        setVisibility(view, R.image.licenseGroup, !mInSlideShow);
        Integer[] icons = PhotoLicence.getIcons(photo);
        setImageView(view, R.image.license1, 0, icons);
        setImageView(view, R.image.license2, 1, icons);
        TextView owner = (TextView) view.findViewById(R.image.owner);
        if (icons.length > 0) {
            owner.setText(photo.getAuthor());
        } else {
            view.findViewById(R.image.licenseGroup).setVisibility(View.GONE);
        }

        String url = photo.getUrl();
        View licenceGroup = view.findViewById(R.image.licenseGroup);
        if (url != null && url.length() > 0) {
            owner.setTextColor(Color.rgb(0x19, 0x49, 0x90));
            owner.setTypeface(null, Typeface.BOLD);

            licenceGroup.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    onReceiveEntry(new NavigationWeb(photo.getUrl()));
                }
            });
        } else {
            owner.setTypeface(null, Typeface.NORMAL);
            owner.setTextColor(Color.WHITE);
            licenceGroup.setOnClickListener(null);
        }

        setupTouchOnPlayButton();
        setVisibility(R.image.play_slideshow, !mInSlideShow && mShowSlideShowControls);
        setVisibility(R.image.loading, mMissingPhoto);
        setVisibility(R.image.wait, mMissingPhoto && isOnline());

        String missingTextTemplate = getString(
                mMissingPhoto && isOnline() ? R.string.missing_photo : R.string.missing_not_online);
        String missingText = String.format(missingTextTemplate, mCurrentImage + 1, getImageCountInSet());

        setText(R.image.missing, missingText);
    }
}

From source file:org.cm.podd.report.activity.ReportActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(mAlertReceiver, new IntentFilter(FollowAlertService.TAG));

    broadcastManager.registerReceiver(new BroadcastReceiver() {
        @Override/*from   w  w  w  .  j  a v  a2 s. c o  m*/
        public void onReceive(Context context, Intent intent) {
            long administrationAreaId = intent.getLongExtra("administrationAreaId", -99);
            setRegionId(administrationAreaId);
        }
    }, new IntentFilter(SyncAdministrationAreaService.TAG));

    sharedPrefUtil = new SharedPrefUtil(this);

    setContentView(R.layout.activity_report);

    Toolbar myToolbar = findViewById(R.id.report_toolbar);
    setSupportActionBar(myToolbar);

    long areaId = sharedPrefUtil.getDefaultAdministrationAreaId();
    if (areaId != -99) {
        setRegionId(areaId);
    }

    formView = findViewById(R.id.form);
    locationView = findViewById(R.id.location);

    textProgressLocationView = findViewById(R.id.progress_location_text);
    textProgressLocationView.setTypeface(StyleUtil.getDefaultTypeface(getAssets(), Typeface.NORMAL));
    countdownTextView = findViewById(R.id.countdownTextView);
    countdownTextView.setTypeface(StyleUtil.getDefaultTypeface(getAssets(), Typeface.NORMAL));
    refreshLocationButton = findViewById(R.id.refresh_location_button);
    refreshLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            requestGPSLocation();
            startLocationSearchTimeoutCountdown();
        }
    });
    progressBar = findViewById(R.id.progressBar);

    prevBtn = findViewById(R.id.prevBtn);
    nextBtn = findViewById(R.id.nextBtn);
    nextBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            nextScreen();
        }
    });
    nextBtn.setTypeface(StyleUtil.getDefaultTypeface(getAssets(), Typeface.NORMAL));
    prevBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    prevBtn.setTypeface(StyleUtil.getDefaultTypeface(getAssets(), Typeface.NORMAL));

    disableMaskView = findViewById(R.id.disableMask);

    reportDataSource = new ReportDataSource(this);
    reportTypeDataSource = new ReportTypeDataSource(this);
    reportQueueDataSource = new ReportQueueDataSource(this);

    recordSpecDataSource = RecordSpecDataSource.Companion.getInstance(this);
    followAlertDataSource = new FollowAlertDataSource(this);

    if (savedInstanceState != null) {
        currentFragment = savedInstanceState.getString("currentFragment");
        reportId = savedInstanceState.getLong("reportId");
        reportType = savedInstanceState.getLong("reportType");
        follow = savedInstanceState.getBoolean("follow");
        testReport = savedInstanceState.getBoolean("testReport");
        formIterator = (FormIterator) savedInstanceState.getSerializable("formIterator");
        if (formIterator != null) {
            trigger = formIterator.getForm().getTrigger();
        }
        reportSubmit = savedInstanceState.getInt("reportSubmit");
        followActionName = savedInstanceState.getString("followActionName");
        Log.d(TAG, "onCreate from savedInstance, testFlag = " + testReport);

        currentLatitude = savedInstanceState.getDouble("currentLatitude");
        currentLongitude = savedInstanceState.getDouble("currentLongitude");
        recordSpec = (RecordSpec) savedInstanceState.get("recordSpec");
        parentReportGuid = savedInstanceState.getString("parentReportGuid");
    } else {
        Intent intent = getIntent();
        String action = intent.getAction();
        int startPageId = -1;
        switch (action) {
        case ACTION_NEW_REPORT:
            reportType = intent.getLongExtra("reportType", 0);
            testReport = intent.getBooleanExtra("test", false);
            reportId = reportDataSource.createDraftReport(reportType, testReport);
            follow = false;
            break;
        case FollowAlertService.ORG_CM_PODD_REPORT_FOLLOW:
            reportType = intent.getLongExtra("reportType", 0);
            testReport = false;
            reportId = intent.getLongExtra("reportId", -99);
            follow = intent.getBooleanExtra("follow", false);
            break;
        case ACTION_FOR_EDIT_OR_VIEW:
            reportType = intent.getLongExtra("reportType", 0);
            testReport = intent.getBooleanExtra("test", false);
            reportId = intent.getLongExtra("reportId", -99);
            break;
        case ACTION_CREATE_FOLLOW_REPORT:
            reportType = intent.getLongExtra("reportType", 0);
            parentReportId = intent.getLongExtra("reportId", -99);
            reportId = reportDataSource.createFollowReport(parentReportId);
            follow = true;
            followActionName = "follow";
            break;
        case ACTION_CREATE_FOLLOW_REPORT_WITH_ACTION:
            reportType = intent.getLongExtra("reportType", 0);
            parentReportId = intent.getLongExtra("reportId", -99);
            reportId = reportDataSource.createFollowReport(parentReportId);
            follow = true;
            followActionName = intent.getStringExtra("followActionName");
            startPageId = intent.getIntExtra("startPageId", -1);
            break;
        case ACTION_CREATE_FOLLOW_REPORT_FROM_RECORD:
            reportType = intent.getLongExtra("reportType", 0);
            parentReportGuid = intent.getStringExtra("parentReportGuid");
            String preloadFormData = intent.getStringExtra("preloadFormData");
            reportId = reportDataSource.createFollowReport(reportType, parentReportGuid, preloadFormData);
            follow = true;
            break;

        }

        Form form = reportTypeDataSource.getForm(reportType);
        trigger = form.getTrigger();
        if (trigger != null) {
            Log.d(TAG, String.format(
                    "This report type contain a trigger with pattern:%s, pageId:%d, notificationText:%s",
                    trigger.getPattern(), trigger.getPageId(), trigger.getNotificationText()));
        }
        if (intent.getAction() != null
                && intent.getAction().equals(FollowAlertService.ORG_CM_PODD_REPORT_FOLLOW)) {
            form.setStartWithTrigger(true);
        }

        if (startPageId != -1) {
            form.setStartPageId(startPageId);
        }

        formIterator = new FormIterator(form);
        Report report = loadFormData(form);
        recordSpec = recordSpecDataSource.getByReportTypeId(report.getType());

        nextScreen();
    }

    if (recordSpec != null) {
        final FirebaseContext firebaseContext = FirebaseContext.Companion
                .getInstance(PreferenceContext.Companion.getInstance(getApplicationContext()));
        firebaseContext.auth(this, new Function1<Boolean, Unit>() {
            @Override
            public Unit invoke(Boolean success) {
                if (success) {
                    recordDataSource = firebaseContext.recordDataSource(recordSpec, parentReportGuid);
                }
                return null;
            }
        });
    }

    // open location service only when
    // 1. Create a New report
    // 2. Edit a draft report which don't have any location attach.
    if ((reportSubmit == 0) && (currentLatitude == 0.00)) {
        buildGoogleApiClient();
        if (formIterator.getForm().isForceLocation()) {
            switchToProgressLocationMode();
        }
    }

    /* check softkeyboard visibility */
    final View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            // different devices' screens have normal height diff differently
            // eg, roughly 5.5" xxhdpi has 220px, 4.5" xhdpi has 110px, 4", 3.5" hdpi has 75px
            int heightDiff = rootView.getRootView().getHeight() - rootView.getHeight();
            int limitHeightPx = (int) (getResources().getDisplayMetrics().density * 100);
            Log.d(TAG, String.format("diff height=%d, limit height=%d", heightDiff, limitHeightPx));
        }
    });

    Tracker tracker = ((PoddApplication) getApplication()).getTracker(PoddApplication.TrackerName.APP_TRACKER);
    tracker.setScreenName("Report-" + reportType);
    tracker.send(new HitBuilders.AppViewBuilder().build());

    startTime = System.currentTimeMillis();
}