Exemplo n.º 1
0
  public void addCrumb(@NonNull Crumb crumb, boolean refreshLayout) {
    LinearLayout view =
        (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.bread_crumb, this, false);
    view.setTag(mCrumbs.size());
    view.setOnClickListener(this);

    ImageView iv = (ImageView) view.getChildAt(1);
    Drawable arrow = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_right_arrow, null);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      assert arrow != null;
      arrow.setAutoMirrored(true);
    }

    iv.setImageDrawable(arrow);
    iv.setVisibility(View.GONE);

    mChildFrame.addView(
        view,
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mCrumbs.add(crumb);
    if (refreshLayout) {
      mActive = mCrumbs.size() - 1;
      requestLayout();
    }
    invalidateActivatedAll();
  }
 private void invalidate() {
   if (mGrid.getAdapter() == null) {
     mGrid.setAdapter(new ColorGridAdapter());
     mGrid.setSelector(
         ResourcesCompat.getDrawable(getResources(), R.drawable.md_transparent, null));
   } else ((BaseAdapter) mGrid.getAdapter()).notifyDataSetChanged();
   if (getDialog() != null) getDialog().setTitle(getTitle());
 }
Exemplo n.º 3
0
 public static void setVideoIndicator(View view, ViewGroup parent) {
   if (view instanceof ForegroundImageView) {
     final Drawable foreground;
     if (isVideoItem(parent)) {
       foreground =
           ResourcesCompat.getDrawable(view.getResources(), R.drawable.ic_card_media_play, null);
     } else {
       foreground = null;
     }
     ((ForegroundImageView) view).setForeground(foreground);
   }
 }
  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    switch (getItemViewType(position)) {
      case TYPE_ACCOUNT:
        Account account = mDataset.get(position);
        VCard vcard =
            VCardUtils.loadLocalProfileFromDisk(
                mContext.getFilesDir(),
                account.getAccountID(),
                mContext.getString(R.string.unknown));
        if (!vcard.getPhotos().isEmpty()) {
          Bitmap photo = BitmapUtils.cropImageToCircle(vcard.getPhotos().get(0).getData());
          ((AccountView) holder).photo.setImageBitmap(photo);
        } else {
          Drawable photo =
              ResourcesCompat.getDrawable(
                  mContext.getResources(), R.drawable.ic_contact_picture, null);
          ((AccountView) holder).photo.setImageDrawable(photo);
        }
        ((AccountView) holder).alias.setText(vcard.getFormattedName().getValue());
        if (account.isRing()) {
          String username = account.getRegisteredName();
          if (!account.registeringUsername && !TextUtils.isEmpty(username)) {
            ((AccountView) holder).host.setText(username);
          } else {
            ((AccountView) holder).host.setText(account.getUsername());
          }
        } else if (account.isSip() && !account.isIP2IP()) {
          ((AccountView) holder).host.setText(account.getUsername() + "@" + account.getHost());
        } else {
          ((AccountView) holder).host.setText(R.string.account_type_ip2ip);
        }

        ((AccountView) holder)
            .error.setVisibility(account.isRegistered() ? View.GONE : View.VISIBLE);
        break;
      case TYPE_ADD_SIP_ACCOUNT:
        ((AddAccountView) holder).icon.setImageResource(R.drawable.ic_add_black_24dp);
        ((AddAccountView) holder).title.setText(R.string.add_sip_account_title);
        break;
      case TYPE_ADD_RING_ACCOUNT:
        ((AddAccountView) holder).icon.setImageResource(R.drawable.ic_add_black_24dp);
        ((AddAccountView) holder).title.setText(R.string.add_ring_account_title);
        break;
      default:
        break;
    }
  }
Exemplo n.º 5
0
 @Override
 public void onLoadingFailed(final String imageUri, final View view, final FailReason reason) {
   if (view == null) return;
   if (view instanceof ForegroundImageView) {
     ((ImageView) view).setImageDrawable(null);
     final Drawable foreground =
         ResourcesCompat.getDrawable(view.getResources(), R.drawable.image_preview_refresh, null);
     ((ForegroundImageView) view).setForeground(foreground);
   }
   mLoadingUris.remove(view);
   final ProgressBar progress = findProgressBar(view.getParent());
   if (progress != null) {
     progress.setVisibility(View.GONE);
   }
 }
  public void initViews(View view) {
    tvVideoLongDescription = (TextView) view.findViewById(R.id.tv_video_long_description);
    tvRelatedTitle = (TextView) view.findViewById(R.id.tv_related_title);
    relatedVideoListview = (ListView) view.findViewById(R.id.relatedVideoList);
    llVideoDescription = (LinearLayout) view.findViewById(R.id.ll_long_description);
    llRelatedVideos = (LinearLayout) view.findViewById(R.id.ll_related_videos);
    scrollView = (ScrollView) view.findViewById(R.id.scroll_view);
    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
      progressBar.setIndeterminateDrawable(
          getResources().getDrawable(R.drawable.circle_progress_bar_lower));
    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
      progressBar.setIndeterminateDrawable(
          ResourcesCompat.getDrawable(getResources(), R.drawable.progress_large_material, null));
    }
    tvRecordsStatus = (TextView) view.findViewById(R.id.tv_records_status);
  }
Exemplo n.º 7
0
  @Nullable
  private static Drawable getBestDrawable(Resources resources, @DrawableRes int id) {
    int[] densities =
        new int[] {
          DisplayMetricsCompat.DENSITY_XXXHIGH,
          DisplayMetricsCompat.DENSITY_XXHIGH,
          DisplayMetricsCompat.DENSITY_XHIGH,
          DisplayMetricsCompat.DENSITY_HIGH // 这都没有狗带吧
        };

    for (int density : densities) {
      try {
        return ResourcesCompat.getDrawableForDensity(resources, id, density, null);
      } catch (Exception ignored) {
      }
    }

    return null;
  }
Exemplo n.º 8
0
  /**
   * Populates the list of activities around.
   *
   * @param list The layout where the event will be placed.
   */
  @SuppressLint(
      "InflateParams") // Views are added from a loop: I can't specify the parent when inflating.
  private void populateAround(LinearLayout list) {

    // A list of events.
    ArrayList<Event> eventList = new ArrayList<Event>();
    Event event;

    // A layout to be populated with an event.
    LinearLayout entry;

    // Touchable layout of each entry
    LinearLayout llTouch;

    // An inflater
    LayoutInflater factory = LayoutInflater.from(view.getContext());

    // TextViews in each row
    TextView tvRowTitle, tvRowDescription, tvRowAddress, tvRowDistance, tvRowTime, tvRowId;

    // Icon next to the location text
    Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.pinpoint, null);
    icon.setBounds(0, 0, 80, 80);

    // Read from database
    SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
    Cursor cursor =
        db.rawQuery(
            "SELECT schedule, gm, event.name, event.description, place.name, address, lat, lon, start, end, host, event.id FROM event, place WHERE schedule = 1 AND event.place = place.id;",
            null);

    // Make the list empty, in case we are not populating it for the first time.
    list.removeAllViews();

    // Elements to parse, format and calculate times.
    Calendar cal;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
    SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
    Date date = new Date();
    Date startMinus30, endMinus15, startPlus30;

    // Decimal formatter to write text
    DecimalFormat df = new DecimalFormat("#.#");

    // Holds the distance between the user and the event
    double distance;

    // Loop thorough every returned row, creating an event for each suitable row.
    while (cursor.moveToNext()) {

      // Operate with dates to see if the event close in time.
      try {
        cal = Calendar.getInstance();
        cal.setTime(dateFormat.parse(cursor.getString(8)));
        cal.add(Calendar.MINUTE, -30);
        startMinus30 = cal.getTime();
        cal = Calendar.getInstance();
        cal.setTime(dateFormat.parse(cursor.getString(8)));
        cal.add(Calendar.MINUTE, 30);
        startPlus30 = cal.getTime();

        // Events with end date
        if (cursor.getString(9) != null) {
          cal = Calendar.getInstance();
          cal.setTime(dateFormat.parse(cursor.getString(9)));
          cal.add(Calendar.MINUTE, -15);
          endMinus15 = cal.getTime();

          // If in range
          if (date.after(startMinus30) && date.before(endMinus15)) {
            event =
                new Event(
                    cursor.getInt(11),
                    cursor.getString(2),
                    cursor.getString(3),
                    cursor.getInt(1),
                    cursor.getInt(0),
                    cursor.getString(4),
                    cursor.getString(10),
                    new double[] {cursor.getDouble(6), cursor.getDouble(7)},
                    cursor.getString(8),
                    cursor.getString(9));
            eventList.add(event);
          }
        }
        // Events without end time
        else {
          if (date.after(startMinus30) && date.before(startPlus30)) {
            event =
                new Event(
                    cursor.getInt(11),
                    cursor.getString(2),
                    cursor.getString(3),
                    cursor.getInt(1),
                    cursor.getInt(0),
                    cursor.getString(4),
                    cursor.getString(10),
                    new double[] {cursor.getDouble(6), cursor.getDouble(7)},
                    cursor.getString(8),
                    cursor.getString(9));
            eventList.add(event);
          }
        }

      } catch (ParseException e) {
        Log.e("Error parsing date for around event", e.toString());
      }
    }

    // Close the cursor and the database
    cursor.close();
    db.close();

    // Sort the event list.
    Collections.sort(eventList);

    // Loop events in the list.
    if (eventList.size() == 0) {
      // If no events around
      list.setVisibility(View.GONE);
      noEvents.setVisibility(View.VISIBLE);
    } else {
      // If there are events being hold now or close in time.
      list.setVisibility(View.VISIBLE);
      noEvents.setVisibility(View.GONE);

      // Loop events
      for (int i = 0; i < eventList.size(); i++) {

        // Create a new row
        entry = (LinearLayout) factory.inflate(R.layout.row_around, null);

        // Set id
        tvRowId = (TextView) entry.findViewById(R.id.tv_row_around_id);
        tvRowId.setText(Integer.toString(eventList.get(i).getId()));

        // Set title
        tvRowTitle = (TextView) entry.findViewById(R.id.tv_row_around_title);
        tvRowTitle.setText(eventList.get(i).getName());

        // Set description
        tvRowDescription = (TextView) entry.findViewById(R.id.tv_row_around_description);
        tvRowDescription.setText(eventList.get(i).getDescription());

        // Set address
        tvRowAddress = (TextView) entry.findViewById(R.id.tv_row_around_address);
        tvRowAddress.setText(eventList.get(i).getPlace());

        // Set distance
        tvRowDistance = (TextView) entry.findViewById(R.id.tv_row_around_distance);
        distance = eventList.get(i).getDistance(coordinates);
        if (distance < 1000) {
          tvRowDistance.setText(
              String.format(
                  getResources().getString(R.string.around_distance),
                  Math.round(distance),
                  getResources().getString(R.string.meters),
                  Math.round(distance * 0.012)));
        } else
          tvRowDistance.setText(
              String.format(
                  getResources().getString(R.string.around_distance),
                  df.format(distance / 1000),
                  getResources().getString(R.string.kilometers),
                  Math.round(distance * 0.012)));

        // Set time
        tvRowTime = (TextView) entry.findViewById(R.id.tv_row_around_time);
        Date tm;
        try {
          tm = eventList.get(i).getStart();
          if (dayFormat.format(tm).equals(dayFormat.format(date)))
            tvRowTime.setText(
                view.getContext().getString(R.string.today) + " " + timeFormat.format(tm));
          else
            tvRowTime.setText(
                view.getContext().getString(R.string.tomorrow) + " " + timeFormat.format(tm));
        } catch (Exception e) {
          Log.e("Around event date error", e.toString());
        }

        // Set touch event that will show a dialog.
        llTouch = (LinearLayout) entry.findViewById(R.id.ll_row_around_content);
        llTouch.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                TextView tvId = (TextView) v.findViewById(R.id.tv_row_around_id);
                int id = Integer.parseInt(tvId.getText().toString());
                Log.e("TOUCH", "#" + id);
                showDialog(id);
              }
            });

        // Add the entry to the list.
        list.addView(entry);
      }
    }
  }
Exemplo n.º 9
0
 @Override
 public Drawable getChanFavicon() {
   return ResourcesCompat.getDrawable(resources, R.drawable.favicon_02ch, null);
 }
Exemplo n.º 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    MyApp.initOnBroadCastReceiver(this);
    super.onCreate(savedInstanceState);
    // prefs = getSharedPreferences("teamproject.glasgow.reminders_app", MODE_PRIVATE);
    prefs = MyApp.getPrefs();

    setContentView(R.layout.activity_reminders);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //        cloudMem = new ParseStorageAdapter(this);
    //        cloudMem.testAddNewTaskToDB();
    //        cloudMem.getRemindersFromDB();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();
    mDrawerList = (ListView) findViewById(R.id.navList);

    addDrawerItems();
    setupDrawer();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    if (prefs.getBoolean("firstrun", true)) {
      reminders = HelperFunctions.generateReminderInitData();
      PersistencyManager.saveReminders(reminders, true);
    } else {
      // reminders = PersistencyManager.getReminders();
      reminders = MyApp.getReminders();
    }

    // reminders = cloudMem.getRemindersFromDB();
    //        cloudMem.searchReminder("a");

    expandableListView = (ExpandableListView) findViewById(R.id.ExpList);

    // Display indicator on the right
    Display newDisplay = getWindowManager().getDefaultDisplay();
    int width = newDisplay.getWidth();
    expandableListView.setIndicatorBounds(width - 100, width);

    ExpAdapter = new ExpandListAdapter(Reminders.this, reminders);
    expandableListView.setAdapter(ExpAdapter);

    // expand all items
    for (int i = 0; i < ExpAdapter.getGroupCount(); i++) {
      expandableListView.expandGroup(i);
    }

    expandableListView.setOnChildClickListener(
        new ExpandableListView.OnChildClickListener() {

          @Override
          public boolean onChildClick(
              ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            Occurrence occurrence = (Occurrence) ExpAdapter.getChild(groupPosition, childPosition);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(
                "teamproject.glasgow.reminders_app",
                "teamproject.glasgow.reminders_app.ModifyReminder");
            intent.putExtra("display_type", "modify_reminder");
            Reminder reminder = occurrence.getReminder();
            intent.putExtra("reminder", reminder);
            intent.putExtra("index", reminders.getReminders().indexOf(reminder));
            // AlarmSetter.cancelRepeatingAlarmForReminder(reminder, null);
            startActivityForResult(intent, 2);
            return true;
          }
        });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {

            // Intent intent = new Intent(view.getContext(), ModifyReminder.class);
            // startActivity(intent);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(
                "teamproject.glasgow.reminders_app",
                "teamproject.glasgow.reminders_app.ModifyReminder");
            intent.putExtra("display_type", "add_reminder");
            startActivityForResult(intent, 1);
          }
        });

    // setButtonColor
    Drawable myFabSrc =
        ResourcesCompat.getDrawable(getResources(), android.R.drawable.ic_input_add, getTheme());
    Drawable white = myFabSrc.getConstantState().newDrawable();
    white.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    fab.setImageDrawable(white);

    _reminders = this;
    MyApp.setReminders(reminders);
    UserID = MyApp.getUserID();
    Intent i = this.getIntent();
    if (i.getBooleanExtra("restart", false)) {
      moveTaskToBack(true);
    }
  }