protected void makeMotionChart(int motionCount, JsonArray datas) {
    motionMiddleText.setText("အဆို");
    mMotionCount.setText(MixUtils.convertToBurmese(String.valueOf(motionCount)) + " ခု");

    PieChart mPieChart = (PieChart) findViewById(R.id.motion_piechart);
    makePieChart(datas, mPieChart, motionPieCont);
  }
Exemple #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_home, container, false);
    ButterKnife.bind(this, view);
    setTypeFace();
    alarm = new AlarmManagerBroadcastReceiver();
    alarm.SetAlarm(getActivity());
    try {
      new CountDownTimer(MixUtils.calculateTimeLeftToVote(), 1000) {
        @Override
        public void onTick(long millisUntilFinished) {

          HashMap<String, String> values = MixUtils.formatTime(millisUntilFinished);
          String monthDay = MixUtils.convertToBurmese(values.get("month_day"));
          String hourMinute = MixUtils.convertToBurmese(values.get("hour_minute"));
          monthDayLeft.setText(monthDay);
          hourMinuteLeft.setText(hourMinute);
          if (monthDay.isEmpty()) {
            monthDayLeft.setVisibility(View.GONE);
          }
        }

        @Override
        public void onFinish() {
          // toVote.setText("ပြောင်းလဲရန်");
          monthDayLeft.setText("အခ\u103Bိန\u103Aရောက\u103Aပ\u103Cီ");
          monthDayLeft.setVisibility(View.VISIBLE);
          hourMinuteLeft.setVisibility(View.GONE);
        }
      }.start();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    faqImg.setColorFilter(getResources().getColor(R.color.white));
    faqImg.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent faqIntent = new Intent(getActivity(), FaqListActivity.class);
            startActivity(faqIntent);
          }
        });

    UserPrefUtils userPrefUtils = new UserPrefUtils(getActivity());
    if (userPrefUtils.isValid()) {
      backdrop.setCardBackgroundColor(getResources().getColor(R.color.accent_color));
      txt_cardview_vote_check.setTextColor(Color.WHITE);
      valid_sign.setImageDrawable(getResources().getDrawable(R.drawable.ic_mark));
    } else {
      backdrop.setCardBackgroundColor(Color.parseColor("#FFC107"));
      valid_sign.setImageDrawable(getResources().getDrawable(R.drawable.ic_exclamation_mark));
      txt_cardview_vote_check.setTextColor(Color.WHITE);
    }
    return view;
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   ButterKnife.bind(this);
   mErrorView.setOnRetryListener(this);
   mProgressBar.setVisibility(View.VISIBLE);
   searchWord = getIntent().getStringExtra("searchWord");
   String unicode =
       MMTextUtils.getInstance(SearchListCandidateActivity.this).zgToUni(searchWord.toString());
   inflateCandidateSearchAdapter(unicode.toString());
   MixUtils.toggleVisibilityWithAnim(mCandidateListRecyclerView, false);
   MixUtils.toggleVisibilityWithAnim(mErrorView, false);
   mCandidateListRecyclerView.setLayoutManager(
       new LinearLayoutManager(
           SearchListCandidateActivity.this, LinearLayoutManager.VERTICAL, false));
   candidateSearchAdapter = new CandidateSearchAdapter();
   candidateSearchAdapter.setOnItemClickListener(SearchListCandidateActivity.this);
 }
  protected void makeQuestionChart(int questionCount, JsonArray datas) {
    mQuestionMiddleText.setText("ကဏ္ဍ");
    mQuestionCount.setText(MixUtils.convertToBurmese(String.valueOf(questionCount)) + " ခု");

    PieChart mPieChart = (PieChart) findViewById(R.id.question_piechart);
    makePieChart(datas, mPieChart, mQuestionPieCont);

    if (isUnicode) {
      mQuestionMiddleText.setTypeface(typefacelight);
      mQuestionCount.setTypeface(typefaceTitle);
    } else {
      MMTextUtils.getInstance(this).prepareMultipleViews(mQuestionMiddleText, mQuestionCount);
    }
  }
  protected void makePieChart(JsonArray datas, PieChart mPieChart, LinearLayout mPieCount) {
    List<String> titles = new ArrayList<String>();
    for (JsonElement element : datas) {
      String title = element.getAsJsonObject().get("issue").getAsString();
      titles.add(title);
    }
    Set<String> unique = new HashSet<String>(titles);

    for (String key : unique) {
      System.out.println(key + ": " + Collections.frequency(titles, key));
      Random rnd = new Random();
      String hexes = colorHexes[rnd.nextInt(colorHexes.length)];
      int color = Color.parseColor(hexes);
      int count = Collections.frequency(titles, key);
      PieModel pieModel = new PieModel(key, count, color);
      mPieChart.addPieSlice(pieModel);
      View piechartLegend =
          getLayoutInflater().inflate(R.layout.piechart_legend_layout, mPieCount, false);
      CircleView piechartIndicator =
          (CircleView) piechartLegend.findViewById(R.id.legend_indicator);
      piechartIndicator.setColorHex(color);
      TextView piechartText = (TextView) piechartLegend.findViewById(R.id.legend_text);
      piechartText.setText(key);
      TextView piechartCount = (TextView) piechartLegend.findViewById(R.id.legend_count);
      piechartCount.setText(MixUtils.convertToBurmese(String.valueOf(count)));

      if (isUnicode) {
        piechartText.setTypeface(typefacelight);
        piechartCount.setTypeface(typefacelight);
      } else {
        MMTextUtils.getInstance(this).prepareMultipleViews(piechartText, piechartCount);
      }

      mPieCount.addView(piechartLegend);
    }
    mPieChart.startAnimation();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_candidate_detail);
    ButterKnife.bind(this);
    // actionbar
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

    typefaceTitle = FontCache.getTypefaceTitle(this);
    typefacelight = FontCache.getTypefaceTitle(this);
    isUnicode = UserPrefUtils.getInstance(this).getTextPref().equals(Config.UNICODE);

    mListener =
        new AppBarLayout.OnOffsetChangedListener() {
          @Override
          public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (collapsingAvatarToolbar.getHeight() + verticalOffset
                < 2 * ViewCompat.getMinimumHeight(collapsingAvatarToolbar)) {
              MixUtils.toggleVisibilityWithAnim(cardView, 1000, false);
            } else {
              MixUtils.toggleVisibilityWithAnim(cardView, 1000, true);
            }
          }
        };

    appbar.addOnOffsetChangedListener(mListener);

    candidate = (Candidate) getIntent().getSerializableExtra(Config.CANDIDATE);
    candidateSearchResult =
        (CandidateSearchResult) getIntent().getSerializableExtra("searchResult");

    if (candidate != null) {
      Glide.with(this)
          .load(candidate.getParty().getPartyFlag())
          .bitmapTransform(new BlurTransformation(getApplicationContext(), 8, 1))
          .into(partyImage);

      Glide.with(this)
          .load(candidate.getPhotoUrl())
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .bitmapTransform(new CropCircleTransformation(this))
          .placeholder(R.drawable.profile_placeholder)
          .into(candidateImage);
      candidateName.setText(candidate.getName());

      Glide.with(this)
          .load(candidate.getParty().getPartyFlag())
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .into(mCandidatePartyFlag);

      if (candidate.getConstituency().getAMPCODE() == null) {
        upperHouseView.setVisibility(View.GONE);
      } else {
        upperHouseView.setVisibility(View.VISIBLE);
        upperHouse.setText(
            MixUtils.amConstituencyName(
                candidate.getConstituency().getName(), candidate.getConstituency().getNumber()));
      }

      mCandidateConstituency.setText(candidate.getConstituency().getName());
      mCandidateDateOfBirth.setText(
          MixUtils.convertToBurmese(String.valueOf(candidate.getBirthDateString())));
      mCandidateEducation.setText(candidate.getEducation());
      mCandidateFather.setText(candidate.getFather().getName());
      mCandidateMother.setText(candidate.getMother().getName());
      mCandidateOccupation.setText(candidate.getOccupation());
      mCandidateRace.setText(candidate.getEthnicity());
      mCandidateReligion.setText(candidate.getReligion());
      mCandidateLegalSlature.setText(candidate.getLegislature());
      mCandidateParty.setText(candidate.getParty().getPartyName());
      mCandidateAddress.setText(candidate.getWardVillage());
      RESTService mRESTService = RESTClient.getService(this);
      if (candidate.getMpid() == null) {
        // mCompareCandidate.setCardBackgroundColor(getResources().getColor(R.color.accent_color_error));
        // mCandidateCompareResult.setText(getResources().getString(R.string.first_time_candidate));
        mQuestionHeaderTv.setVisibility(View.GONE);
        mMotionHeaderTv.setVisibility(View.GONE);
        mCandidateQuestionCard.setVisibility(View.GONE);
        mCandidateMotionCard.setVisibility(View.GONE);
      } else {

        Call<JsonObject> questionMotionCall =
            mRESTService.getQuestionAndMotion(candidate.getMpid());
        questionMotionCall.enqueue(
            new RestCallback<JsonObject>() {
              @Override
              public void onResponse(Response<JsonObject> response) {
                if (response.code() == 200) {
                  int motionCount = response.body().get("motions_count").getAsInt();
                  JsonArray motions = response.body().get("motions").getAsJsonArray();

                  int questionCount = response.body().get("questions_count").getAsInt();
                  JsonArray questions = response.body().get("questions").getAsJsonArray();

                  makeMotionChart(motionCount, motions);
                  makeQuestionChart(questionCount, questions);
                }
              }
            });
      }
    } else {
      // TODO fetch Candidate by ID
      /* RESTService mRESTService = RESTClient.getService(this);
      Map<String, String> amyotharParams = new HashMap<>();
      amyotharParams.put(Config.WITH, "party");
      Call<JsonObject> candidateCall =
          mRESTService.getCandidate("7abd75a22042fe8e3faf931d710949fe", amyotharParams);
      candidateCall.enqueue(new RestCallback<JsonObject>() {
        @Override public void onResponse(Response<JsonObject> response) {

        }
      });*/
    }

    mCompareCandidate.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(CandidateDetailActivity.this, CandidateListActivity.class);
            i.putExtra(Config.CANDIDATE, candidate);
            startActivity(i);
          }
        });

    setTypeFace();
  }