Home | History | Annotate | Download | only in home
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.home;
     18 
     19 import android.content.ComponentName;
     20 import android.content.Intent;
     21 import android.graphics.drawable.Drawable;
     22 
     23 /**
     24  * Represents a launchable application. An application is made of a name (or title), an intent
     25  * and an icon.
     26  */
     27 class ApplicationInfo {
     28     /**
     29      * The application name.
     30      */
     31     CharSequence title;
     32 
     33     /**
     34      * The intent used to start the application.
     35      */
     36     Intent intent;
     37 
     38     /**
     39      * The application icon.
     40      */
     41     Drawable icon;
     42 
     43     /**
     44      * When set to true, indicates that the icon has been resized.
     45      */
     46     boolean filtered;
     47 
     48     /**
     49      * Creates the application intent based on a component name and various launch flags.
     50      *
     51      * @param className the class name of the component representing the intent
     52      * @param launchFlags the launch flags
     53      */
     54     final void setActivity(ComponentName className, int launchFlags) {
     55         intent = new Intent(Intent.ACTION_MAIN);
     56         intent.addCategory(Intent.CATEGORY_LAUNCHER);
     57         intent.setComponent(className);
     58         intent.setFlags(launchFlags);
     59     }
     60 
     61     @Override
     62     public boolean equals(Object o) {
     63         if (this == o) {
     64             return true;
     65         }
     66         if (!(o instanceof ApplicationInfo)) {
     67             return false;
     68         }
     69 
     70         ApplicationInfo that = (ApplicationInfo) o;
     71         return title.equals(that.title) &&
     72                 intent.getComponent().getClassName().equals(
     73                         that.intent.getComponent().getClassName());
     74     }
     75 
     76     @Override
     77     public int hashCode() {
     78         int result;
     79         result = (title != null ? title.hashCode() : 0);
     80         final String name = intent.getComponent().getClassName();
     81         result = 31 * result + (name != null ? name.hashCode() : 0);
     82         return result;
     83     }
     84 }
     85