private static void addDetectedValueHeader(
     @NonNull ListView listView,
     @StringRes int labelRes,
     @NonNull String labelKey,
     @NonNull String labelValue,
     @NonNull String value,
     @NonNull Icon icon) {
   final TextView textView =
       (TextView)
           LayoutInflater.from(listView.getContext())
               .inflate(R.layout.edx_selectable_list_item, listView, false);
   {
     final SpannableString labelValueSpan = new SpannableString(labelValue);
     labelValueSpan.setSpan(
         new ForegroundColorSpan(
             listView.getResources().getColor(R.color.edx_grayscale_neutral_dark)),
         0,
         labelValueSpan.length(),
         Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
     textView.setText(
         ResourceUtil.getFormattedString(
             listView.getContext().getResources(), labelRes, labelKey, labelValueSpan));
   }
   Context context = textView.getContext();
   TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
       textView,
       new IconDrawable(context, icon)
           .sizeRes(context, R.dimen.edx_base)
           .colorRes(context, R.color.edx_grayscale_neutral_light),
       null,
       null,
       null);
   listView.addHeaderView(textView, new FormOption(labelValue, value), true);
 }
 /**
  * Constructs a new swipe-to-dismiss touch listener for the given list view.
  *
  * @param listView The list view whose items should be dismissable.
  * @param callback The callback to trigger when the user has indicated that she would like to
  *     dismiss one or more list items.
  */
 public SwipeDismissListViewTouchListener(ListView listView, OnDismissCallback callback) {
   ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mListView = listView;
   mCallback = callback;
 }
 /**
  * Constructs a new swipe-to-dismiss touch listener for the given list view.
  *
  * @param listView The list view whose items should be dismissable.
  * @param callbacks The callback to trigger when the user has indicated that she would like to
  *     dismiss one or more list items.
  */
 public SwipeDismissListViewTouchListener(ListView listView, DismissCallbacks callbacks) {
   ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mListView = listView;
   mCallbacks = callbacks;
   swipeDistanceDivisor =
       listView.getContext().getResources().getInteger(R.integer.list_card_swipe_distance_divisor);
 }
Ejemplo n.º 4
0
  public ListViewSwipeGesture(ListView listView, TouchCallbacks Callbacks, Activity context) {
    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mListView = listView;
    activity = context;
    tcallbacks = Callbacks;
    SwipeType = Double;
    GetResourcesValues();

    mListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(
              AdapterView<?> arg0,
              View arg1,
              int arg2,
              long arg3) { // Invokes OnClick Functionality

            if (!moptionsDisplay && DeltaX == 0.0) {
              tcallbacks.OnClickListView(temp_position);
            } else {
              if (old_mDownView != null && mDownView != old_mDownView) {
                ResetListItem(old_mDownView);
                old_mDownView = null;
                mDownView = null;
              }
            }
          }
        });
  }
  /**
   * This simple implementation creates a Bitmap copy of the list item currently shown at ListView
   * <code>position</code>.
   */
  @Override
  public View onCreateFloatView(int position) {
    // Guaranteed that this will not be null? I think so. Nope, got
    // a NullPointerException once...
    View v =
        mListView.getChildAt(
            position + mListView.getHeaderViewsCount() - mListView.getFirstVisiblePosition());

    if (v == null) {
      return null;
    }

    v.setPressed(false);

    // Create a copy of the drawing cache so that it does not get
    // recycled by the framework when the list tries to clean up memory
    // v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    v.setDrawingCacheEnabled(true);
    mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    if (mImageView == null) {
      mImageView = new ImageView(mListView.getContext());
    }
    mImageView.setBackgroundColor(mFloatBGColor);
    mImageView.setPadding(0, 0, 0, 0);
    mImageView.setImageBitmap(mFloatBitmap);
    mImageView.setLayoutParams(new ViewGroup.LayoutParams(v.getWidth(), v.getHeight()));

    return mImageView;
  }
  @Override
  protected void onPostExecute(String result) {

    super.onPostExecute(result);

    if (jsonArray != null && proAdapter == null) {

      proAdapter = new FeaturedListAdapter(featuredListView.getContext(), generateData(jsonArray));

      featuredListView.setAdapter(proAdapter);

      featuredListView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

              int c**k = view.getId();

              Intent i = new Intent(activity, CoachProfile.class);

              i.putExtra("coachID", "" + c**k);
              // i.putExtra("coachName", ""+)
              activity.startActivity(i);
            }
          });

    } else {

      Log.d("emptyarray", "sptmey man");
    }

    // now array

  } // end
Ejemplo n.º 7
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   int hitMovie = info.position;
   HashMap hMap = (HashMap) lv.getItemAtPosition(hitMovie);
   String selMovieNumber = hMap.get("id").toString();
   switch (item.getItemId()) {
     case R.id.edit_movie:
       String selMovieName = hMap.get("title").toString();
       // String selRating = hMap.get("rating").toString();
       // String selDate = hMap.get("date").toString();
       editMovie(Integer.parseInt(selMovieNumber), selMovieName);
       return true;
     case R.id.delete_movie:
       mHelper.RemoveMovie(selMovieNumber, lv.getContext());
       try {
         populateMyMovies(lv);
       } catch (ParseException e) {
         e.printStackTrace();
       }
       return true;
     default:
       return super.onContextItemSelected(item);
   }
 }
  public View headerView(String title) {
    LinearLayout ll = new LinearLayout(listView.getContext());
    ll.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams =
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    layoutParams.setMargins(10, 3, 0, 0);

    TextView tv = new TextView(listView.getContext());
    tv.setText(title);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tv.setTypeface(null, Typeface.BOLD);
    tv.setTextColor(0xFFFFFFFF);
    ll.setBackgroundColor(0xFF818A93);

    ll.addView(tv, layoutParams);

    return ll;
  }
Ejemplo n.º 9
0
 private void GetResourcesValues() {
   mAnimationTime =
       mListView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   HalfColor = RangeOneColor; // Green
   FullColor = activity.getResources().getString(R.string.str_red); // Orange
   HalfText = activity.getResources().getString(R.string.basic_action_1);
   HalfTextFinal = activity.getResources().getString(R.string.basic_action_1);
   FullText = activity.getResources().getString(R.string.basic_action_2);
   FullTextFinal = activity.getResources().getString(R.string.basic_action_2);
   //        HalfDrawable        =   activity.getResources().getDrawable( R.drawable.rating_good );
   //        FullDrawable        =
   // activity.getResources().getDrawable(R.drawable.content_discard);
 }
Ejemplo n.º 10
0
 /* Alle Daten des ausgewählten Tages anzeigen
  * ------------------------------------------*/
 private void setCurrentDay() {
   tvDay.setText(days[curDay]);
   db = new DB_DatabaseHelper();
   // SQL-Abfrage durchführen Cursor holen
   dbCursor =
       db.query(
           getString(R.string.table_stundenplan),
           getString(R.string.field_tag) + " = '" + days[curDay] + "'",
           getString(R.string.field_stunde) + " ASC");
   startManagingCursor(dbCursor);
   // CursorAdapter zum befüllen der Liste initialisieren und an Liste übergeben
   listAdapter = new PlanListAdapter(planListe.getContext(), dbCursor, true);
   planListe.setAdapter(listAdapter);
 }
Ejemplo n.º 11
0
  /**
   * Called when the async task for requesting data has returned,
   *
   * @param routeResponse
   */
  public void setRouteResponse(RouteResponse routeResponse) {

    if (routeResponse == null) {
      return;
    }

    Route route = routeResponse.route;
    if (route == null) {
      return;
    }

    List<Location> locations = route.locations;
    if (locations.size() == 0) {
      return;
    }

    distanceUnit = "M".equals(route.options.unit) ? "mi" : "km";
    start.setText(route.locations.get(0).toString());
    end.setText(route.locations.get(route.locations.size() - 1).toString());
    distance.setText(new DecimalFormat("#.##").format(route.distance) + " " + distanceUnit);
    time.setText(route.formattedTime);

    List<Leg> legs = routeResponse.route.legs;
    ManueverArrayAdapter arrayAdapter =
        new ManueverArrayAdapter(
            narrativeList.getContext(), R.layout.custom_route_manuver, routeResponse);

    narrativeList.setAdapter(arrayAdapter);
    if (legs != null) {
      for (Leg leg : legs) {
        List<Maneuver> manuevers = leg.maneuvers;
        if (manuevers != null) {
          int i = 1;
          for (Maneuver manuever : manuevers) {
            arrayAdapter.add(manuever);
            // Log.d("location", "maneuver " + i + " is " + manuever.startPoint.toString());
            i++;
          }
        }
      }
    }

    narrativeList.invalidate();
  }
Ejemplo n.º 12
0
  /**
   * This method will load and fill the navigation drawer with the contents specified here. After
   * the drawer has been filled the method will bind a listener to it.
   *
   * @param activeActivity The activity currently activated.
   * @param listView The empty navigation drawer.
   * @return The navigation drawer filled with the necessary data.
   */
  public static ListView setNavigationDrawerAdapter(Class activeActivity, ListView listView) {
    List<NavigationItem> navigationItemList = new ArrayList<>();
    Context context = listView.getContext();
    Resources resources = context.getResources();
    navigationItemList.add(
        new NavigationItem(
            resources.getString(R.string.anime_list_activity_title),
            ContextCompat.getDrawable(context, R.drawable.ic_action_list),
            AnimeListActivity.class));
    navigationItemList.add(
        new NavigationItem(
            resources.getString(R.string.anime_main_activity_title),
            ContextCompat.getDrawable(context, R.drawable.ic_action_calander),
            MainActivity.class));

    NavigationDrawerListAdapter adapter =
        new NavigationDrawerListAdapter(context, navigationItemList);
    adapter.setActiveNavigationItem(activeActivity);

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(adapter.getClickListener(context));

    return listView;
  }
Ejemplo n.º 13
0
  private void ensureUiListView() {

    // if(mListAdapter == null){
    mListAdapter = new SeparatedListAdapter(this);
    // }

    if (mStateHolder.getSortMethod() == SORT_METHOD_RECENT) {
      sortRecommendsRecent(mStateHolder.getRecommends(), mListAdapter);
    } else {
      sortRecommendsDistance(mStateHolder.getRecommends(), mListAdapter);
    }
    listView = getListView();
    listView.setAdapter(mListAdapter);
    listView.setDividerHeight(0);

    listView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RecommendMsg recommend = (RecommendMsg) parent.getAdapter().getItem(position);
            if (recommend != null) {
              Intent intent = new Intent(FriendsActivity.this, RecommendDetailsActivity.class);
              intent.putExtra(RecommendDetailsActivity.EXTRA_RecommendMsg_PARCEL, recommend);
              startActivity(intent);
            }
          }
        });

    footerview =
        (LinearLayout)
            LayoutInflater.from(listView.getContext())
                .inflate(R.layout.recommend_list_footer, null);

    footerview.setClickable(true);
    footerview.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            mStateHolder.setCurrentListItem(listView.getCount());

            mStateHolder.startTask(FriendsActivity.this);
          }
        });
    footerview.setVisibility(View.VISIBLE);
    if (!mStateHolder.getRanOnce()) {
      listView.addFooterView(footerview);
    }

    // Prepare our no-results view. Something odd is going on with the layout parameters though.
    // If we don't explicitly set the layout to be fill/fill after inflating, the layout jumps
    // to a wrap/wrap layout. Furthermore, sdk 3 crashes with the original layout using two
    // buttons in a horizontal LinearLayout.
    LayoutInflater inflater = LayoutInflater.from(this);

    if (UiUtil.sdkVersion() > 3) {
      mLayoutEmpty = (ScrollView) inflater.inflate(R.layout.friends_activity_empty, null);

      Button btnAddFriends =
          (Button) mLayoutEmpty.findViewById(R.id.friendsActivityEmptyBtnAddFriends);
      btnAddFriends.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              /*
              Intent intent = new Intent(FriendsActivity.this, AddFriendsActivity.class);
              startActivity(intent);*/
            }
          });

      Button btnFriendRequests =
          (Button) mLayoutEmpty.findViewById(R.id.friendsActivityEmptyBtnFriendRequests);
      btnFriendRequests.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              /*
              Intent intent = new Intent(FriendsActivity.this, FriendRequestsActivity.class);
              startActivity(intent);*/
            }
          });

    } else {
      // Inflation on 1.5 is causing a lot of issues, dropping full layout.
      mLayoutEmpty = (ScrollView) inflater.inflate(R.layout.friends_activity_empty_sdk3, null);
    }

    mLayoutEmpty.setLayoutParams(
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));

    if (mListAdapter.getCount() == 0) {
      setEmptyView(mLayoutEmpty);
    }

    if (mStateHolder.getIsRunningTask()) {
      setProgressBarIndeterminateVisibility(true);
      if (!mStateHolder.getRanOnce()) {
        setLoadingView();
      }
    } else {
      setProgressBarIndeterminateVisibility(false);
    }
  }
Ejemplo n.º 14
0
package com.chang.news.util;
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle(formField.getLabel());
    final List<FormOption> options = new ArrayList<>();
    final FormOptions formOptions = formField.getOptions();
    final ArrayAdapter<FormOption> adapter =
        new ArrayAdapter<>(getActivity(), R.layout.edx_selectable_list_item, options);
    if (formOptions.getReference() != null) {
      new GetFormOptionsTask(getActivity(), formOptions.getReference()) {
        @Override
        protected void onSuccess(List<FormOption> formOptions) throws Exception {
          options.addAll(formOptions);
          adapter.notifyDataSetChanged();
          selectCurrentOption();
        }
      }.execute();

    } else if (formOptions.getRangeMin() != null && formOptions.getRangeMax() != null) {
      for (int i = formOptions.getRangeMax(); i >= formOptions.getRangeMin(); --i) {
        options.add(new FormOption(String.valueOf(i), String.valueOf(i)));
      }
    } else if (formOptions.getValues() != null && formOptions.getValues().size() > 0) {
      options.addAll(formOptions.getValues());
    }
    if (!TextUtils.isEmpty(formField.getInstructions())) {
      final View instructionsContainer =
          LayoutInflater.from(view.getContext())
              .inflate(R.layout.form_field_instructions_header, listView, false);
      final TextView instructions =
          (TextView) instructionsContainer.findViewById(R.id.instructions);
      final TextView subInstructions =
          (TextView) instructionsContainer.findViewById(R.id.sub_instructions);
      instructions.setText(formField.getInstructions());
      if (TextUtils.isEmpty(formField.getSubInstructions())) {
        subInstructions.setVisibility(View.GONE);
      } else {
        subInstructions.setText(formField.getSubInstructions());
      }
      listView.addHeaderView(instructionsContainer, null, false);
    }
    if (null != formField.getDataType()) {
      switch (formField.getDataType()) {
        case COUNTRY:
          {
            final Locale locale = Locale.getDefault();
            addDetectedValueHeader(
                listView,
                R.string.edit_user_profile_current_location,
                "current_location",
                locale.getDisplayCountry(),
                locale.getCountry(),
                FontAwesomeIcons.fa_map_marker);
            break;
          }
        case LANGUAGE:
          {
            final Locale locale = Locale.getDefault();
            addDetectedValueHeader(
                listView,
                R.string.edit_user_profile_current_language,
                "current_language",
                locale.getDisplayLanguage(),
                locale.getLanguage(),
                FontAwesomeIcons.fa_comment);
            break;
          }
      }
    }
    if (formField.getOptions().isAllowsNone()) {
      final TextView textView =
          (TextView)
              LayoutInflater.from(listView.getContext())
                  .inflate(R.layout.edx_selectable_list_item, listView, false);
      final String label = formField.getOptions().getNoneLabel();
      textView.setText(label);
      listView.addHeaderView(textView, new FormOption(label, null), true);
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final FormOption item = (FormOption) parent.getItemAtPosition(position);
            getActivity()
                .setResult(
                    Activity.RESULT_OK,
                    new Intent()
                        .putExtra(FormFieldActivity.EXTRA_FIELD, formField)
                        .putExtra(FormFieldActivity.EXTRA_VALUE, item.getValue()));
            getActivity().finish();
          }
        });
    selectCurrentOption();
  }
Ejemplo n.º 16
0
  @Override
  protected void onResume() {
    super.onResume();

    Cache cache = new Cache();
    cache.load(this);

    // Populate Recipe List
    ListView list = (ListView) findViewById(R.id.recipe_list);
    list.setAdapter(new RecipeAdapter(list.getContext(), R.layout.item_recipe, cache.getRecipes()));

    list.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          public boolean onItemLongClick(
              AdapterView<?> arg0, View arg1, final int position, long id) {
            Log.d("Testing", "On Clicked!");
            AlertDialog.Builder builder = new AlertDialog.Builder(ActivityViewRecipeList.this);

            final Cache cache = new Cache();
            cache.load(ActivityViewRecipeList.this);

            final Recipe recipe = cache.getRecipe(id);

            builder.setMessage("Remove " + recipe.getTitle() + "?");
            builder.setPositiveButton(
                "Remove",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {

                    cache.removeRecipe(recipe);

                    cache.save(ActivityViewRecipeList.this);

                    onResume();

                    dialog.dismiss();
                  }
                });
            builder.setNegativeButton(
                "Cancel",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                });

            builder.create();
            builder.show();

            return true;
          }
        });

    list.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
            Intent intent = new Intent(ActivityViewRecipeList.this, ActivityViewRecipe.class);
            intent.putExtra("RECIPE_ID", id);
            startActivity(intent);
          }
        });
  }
Ejemplo n.º 17
0
 public ServiceAdapter(ListView list, Cursor c) {
   super(list.getContext(), c);
   this.list = list;
   list.setAdapter(this);
 }
  /**
   * Constructs a new swipe-to-dismiss touch listener for the given list view.
   *
   * @param listView The list view whose items should be dismissable.
   * @param callback The callback to trigger when the user has indicated that she would like to
   *     dismiss one or more list items.
   * @param mode The mode this list handles multiple undos.
   */
  public SwipeDismissList(ListView listView, OnDismissCallback callback, UndoMode mode) {

    if (listView == null) {
      throw new IllegalArgumentException("listview must not be null.");
    }

    mHandler = new HideUndoPopupHandler();
    mListView = listView;
    mCallback = callback;
    mMode = mode;

    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime =
        listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);

    mDensity = mListView.getResources().getDisplayMetrics().density;

    // -- Load undo popup --
    LayoutInflater inflater =
        (LayoutInflater) mListView.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.undo_popup, null);
    mUndoButton = (Button) v.findViewById(R.id.undo);
    mUndoButton.setOnClickListener(new UndoHandler());
    mUndoButton.setOnTouchListener(
        new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            // If user tabs "undo" button, reset delay time to remove popup
            mDelayedMsgId++;
            return false;
          }
        });
    mUndoText = (TextView) v.findViewById(R.id.text);

    mUndoPopup = new PopupWindow(v);
    mUndoPopup.setAnimationStyle(R.style.fade_animation);
    // Get scren width in dp and set width respectively
    int xdensity =
        (int) (mListView.getContext().getResources().getDisplayMetrics().widthPixels / mDensity);
    if (xdensity < 300) {
      mUndoPopup.setWidth((int) (mDensity * 280));
    } else if (xdensity < 350) {
      mUndoPopup.setWidth((int) (mDensity * 300));
    } else if (xdensity < 500) {
      mUndoPopup.setWidth((int) (mDensity * 330));
    } else {
      mUndoPopup.setWidth((int) (mDensity * 450));
    }
    mUndoPopup.setHeight((int) (mDensity * 56));
    // -- END Load undo popu --

    listView.setOnTouchListener(this);
    listView.setOnScrollListener(this.makeScrollListener());

    switch (mode) {
      case SINGLE_UNDO:
        mUndoActions = new ArrayList<Undoable>(1);
        break;
      default:
        mUndoActions = new ArrayList<Undoable>(10);
        break;
    }
  }