我的应用在平板电脑

时间:2015-12-30 09:40:40

标签: android responsive-design tablet

我的应用程序在移动设备上非常完美,但是当我尝试在平板电脑上运行它时,它没有显示任何内容或任何错误,我在Genymotion模拟器(Google Nexus 9)上运行它。
我会在这里发布我的日志,代码和Xml_layouts。

这也出现在我的事件日志

12:17:25 PM Can't bind to local 8636 for debugger
12:17:28 PM An established connection was aborted by the software in your host machine
        java.io.IOException: An established connection was aborted by the software in your host machine

Manifiest

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"
        android:configChanges="orientation|screenSize|keyboardHidden"
    >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".DetailedActivity"
        android:label="@string/title_activity_detailed"
        android:theme="@style/AppTheme.NoActionBar"
        android:configChanges="orientation|screenSize|keyboardHidden"
        >
    </activity>
</application>

日志

12-30 04:04:32.022 624-1069/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.ahmed.popularmovies/.MainActivity (has extras)} from uid 10039 on display 0
12-30 04:04:32.023 624-693/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client
12-30 04:04:32.122 624-1069/system_process V/WindowManager: addAppToken: AppWindowToken{f0d2b97 token=Token{25cc7616 ActivityRecord{206e6f31 u0 com.example.ahmed.popularmovies/.MainActivity t14}}} to stack=1 task=14 at 0
12-30 04:04:32.177 624-648/system_process V/WindowManager: Adding window Window{25431ee u0 Starting com.example.ahmed.popularmovies} at 3 of 8 (after Window{2b77accb u0 com.android.music/com.android.music.ArtistAlbumBrowserActivity})
12-30 04:04:32.495 10401-10401/? I/art: Late-enabling -Xcheck:jni
12-30 04:04:32.502 624-1060/system_process I/ActivityManager: Start proc 10401:com.example.ahmed.popularmovies/u0a60 for activity com.example.ahmed.popularmovies/.MainActivity
12-30 04:04:33.754 69-69/? D/: Socket deconnection
12-30 04:04:33.913 10401-10418/com.example.ahmed.popularmovies D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-30 04:04:33.951 10401-10401/com.example.ahmed.popularmovies D/: HostConnection::get() New Host Connection established 0xf3e34a00, tid 10401
12-30 04:04:33.976 10401-10401/com.example.ahmed.popularmovies D/Atlas: Validating map...
12-30 04:04:33.995 624-11052/system_process V/WindowManager: Adding window Window{30fa2887 u0 com.example.ahmed.popularmovies/com.example.ahmed.popularmovies.MainActivity} at 3 of 9 (before Window{25431ee u0 Starting com.example.ahmed.popularmovies})
12-30 04:04:34.191 10401-10418/com.example.ahmed.popularmovies D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
12-30 04:04:34.198 10401-10418/com.example.ahmed.popularmovies D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
12-30 04:04:34.258 10401-10418/com.example.ahmed.popularmovies D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
12-30 04:04:34.310 10401-10418/com.example.ahmed.popularmovies D/: HostConnection::get() New Host Connection established 0xf3e34b60, tid 10418
12-30 04:04:34.457 10401-10418/com.example.ahmed.popularmovies I/OpenGLRenderer: Initialized EGL, version 1.4
12-30 04:04:35.630 624-706/system_process D/TaskPersister: removeObsoleteFile: deleting file=12_task.xml
12-30 04:04:35.631 624-706/system_process D/TaskPersister: removeObsoleteFile: deleting file=12_task_thumbnail.png
12-30 04:04:35.762 69-69/? D/: Socket deconnection
12-30 04:04:36.060 10401-10418/com.example.ahmed.popularmovies D/OpenGLRenderer: Enabling debug mode 0
12-30 04:04:36.282 10401-10418/com.example.ahmed.popularmovies W/EGL_emulation: eglSurfaceAttrib not implemented
12-30 04:04:36.282 10401-10418/com.example.ahmed.popularmovies W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3ee9680, error=EGL_SUCCESS
12-30 04:04:36.567 10401-10401/com.example.ahmed.popularmovies I/Choreographer: Skipped 153 frames!  The application may be doing too much work on its main thread.
12-30 04:04:36.741 10401-10418/com.example.ahmed.popularmovies V/RenderScript: 0xf3da0c00 Launching thread(s), CPUs 2
12-30 04:04:36.976 624-648/system_process I/ActivityManager: Displayed com.example.ahmed.popularmovies/.MainActivity: +4s669ms
12-30 04:04:37.178 10401-10401/com.example.ahmed.popularmovies V/debug: com.example.ahmed.popularmovies.movieAdapter@c9cb5d4
12-30 04:04:37.288 10401-10401/com.example.ahmed.popularmovies W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
12-30 04:04:37.568 10401-10401/com.example.ahmed.popularmovies W/InputMethodManager: Ignoring onBind: cur seq=26, given seq=25
12-30 04:04:37.673 10401-10409/com.example.ahmed.popularmovies W/art: Suspending all threads took: 5.839ms
12-30 04:04:37.699 10401-10414/com.example.ahmed.popularmovies I/art: Background sticky concurrent mark sweep GC freed 5221(317KB) AllocSpace objects, 6(143KB) LOS objects, 30% free, 1361KB/1954KB, paused 7.964ms total 124.405ms
12-30 04:04:37.774 69-69/? D/: Socket deconnection
12-30 04:04:39.770 69-69/? D/: Socket deconnection

MainActivity

public class MainActivity extends AppCompatActivity {

public static final String popluar = "popularity.desc";
public static final String top_rate = "vote_average.desc";
public static Context context;
public static ArrayList<Movie> movies = new ArrayList<>();
public static FragmentManager fm;
public static Configuration config;


public static String id;
public static String title;
public static String releaseDate;
public static String overView;
public static String voteAverage;
public static String popularity;
public static String poster;

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

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

    context = MainActivity.this;
    fm = getSupportFragmentManager();
    config = getResources().getConfiguration();

    ReplaceFragments(popluar);


}

public static boolean isTablet() {
    if (config.smallestScreenWidthDp >= 600) {
        return true;
    }else {
        return false;
    }
}

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.most_popular) {
        ReplaceFragments(popluar);
        return true;
    }
    if (id == R.id.highest_rated) {
        ReplaceFragments(top_rate);
        return true;
    }
    if (id == R.id.favorite) {
        ReplaceFragments("fav");
        return true;
    }
    return super.onOptionsItemSelected(item);
}

private void ReplaceFragments(String SortBy) {
    if (isTablet()){
        MainFragment mainFragment = MainFragment.newInstance(SortBy);
        getSupportFragmentManager().beginTransaction().replace(R.id.tabletMain, mainFragment)
                .commit();
    }else{
        MainFragment mainFragment = MainFragment.newInstance(SortBy);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragmentMain, mainFragment)
                .commit();
    }

}

public static void showDetails(int position) {
    id = movies.get(position).getId();
    title = movies.get(position).getTitle();
    releaseDate = movies.get(position).getReleaseDate();
    overView = movies.get(position).getOverView();
    voteAverage = movies.get(position).getVoteAverage();
    popularity = movies.get(position).getPopularity();
    poster = movies.get(position).getLargePoster();

    if (isTablet()) {
        DetailFragment detailFragment = new DetailFragment();
        fm.beginTransaction().replace(R.id.tabletDetail, detailFragment)
                .commit();
    } else {
        Intent intent = new Intent(context, DetailedActivity.class);
        context.startActivity(intent);
    }

}

}

MainFragment

public class MainFragment extends Fragment {

public final static String API_KEY = "b932ba435fc93a5944938fe9d44cd198";
public final String BASE_URL = "http://api.themoviedb.org/3/discover/movie?sort_by=&api_key=";

movieAdapter adapter;
movieAdapter DbAdapter;
GridView gridview;
DbOpenHelper dbOpenHelper;
Context context;
String sortOrder;


public MainFragment() {
}

public static MainFragment newInstance(String sortOrder) {
    Bundle args = new Bundle();
    args.putString("SORT", sortOrder);
    MainFragment fragment = new MainFragment();
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        sortOrder = getArguments().getString("SORT");
        if (sortOrder == "fav") {
            new FetchDataFromDb().execute();
        } else {
            new FetchDataFromApi(sortOrder).execute();
        }
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    gridview = (GridView) view.findViewById(R.id.gridView);
    context = getActivity();
    adapter = new movieAdapter(context, R.layout.movie_item, MainActivity.movies);
    return view;
}

class FetchDataFromApi extends AsyncTask<String, Void, Boolean> {
    String SORT_CATEGORY;

    FetchDataFromApi(String paramUrl) {
        SORT_CATEGORY = paramUrl;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        HttpURLConnection urlConnection = null;
        try {
            Uri uriBuilder = Uri.parse(BASE_URL).buildUpon()
                    .appendQueryParameter("sort_by", SORT_CATEGORY)
                    .appendQueryParameter("api_key", API_KEY)
                    .build();
            URL url = new URL(uriBuilder.toString());
            urlConnection = (HttpURLConnection) url.openConnection();

            InputStream in = urlConnection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
            String response = sb.toString();
            ParseJsonData(response);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } finally {
            urlConnection.disconnect();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        gridview.setAdapter(adapter);
        Log.v("debug", String.valueOf(gridview.getAdapter()));
        if (MainActivity.isTablet()) {
            /*MainActivity.showDetails(0);*/
        }
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long ss) {
                MainActivity.showDetails(position);
            }
        });
    }
}

private void ParseJsonData(String response) throws JSONException {
    String PosterBaseUrl = "http://image.tmdb.org/t/p/";
    String LargePoster = "w185";
    String SmallPoster = "";
    final String RESULTS = "results";
    final String ORIGINAL_TITLE = "original_title";
    final String OVERVIEW = "overview";
    final String RELEASE_DATE = "release_date";
    final String POSTER_PATH = "poster_path";
    final String VOTE_AVERAGE = "vote_average";
    final String POPULARITY = "popularity";
    final String ID = "id";

    MainActivity.movies.clear();

    JSONObject jsono = new JSONObject(response);
   // Log.v("Json", response);
    JSONArray jarray = jsono.getJSONArray(RESULTS);
    for (int i = 0; i < jarray.length(); i++) {
        JSONObject object = jarray.getJSONObject(i);
        String id = object.getString(ID);
        String title = object.getString(ORIGINAL_TITLE);
        String releaseDate = object.getString(RELEASE_DATE);
        String overView = object.getString(OVERVIEW);
        String voteAverage = object.getString(VOTE_AVERAGE);
        String popularity = object.getString(POPULARITY);
        String posterPath = object.getString(POSTER_PATH);
        String BigPoster = PosterBaseUrl + LargePoster + posterPath;
        String MinPoster = PosterBaseUrl + SmallPoster + posterPath;

        Movie m = new Movie();
        m.setId(id);
        m.setTitle(title);
        m.setReleaseDate(releaseDate);
        m.setOverView(overView);
        m.setVoteAverage(voteAverage);
        m.setPopularity(popularity);
        m.setLargePoster(BigPoster);
        m.setMinPoster(MinPoster);
        MainActivity.movies.add(m);
    }
}

class FetchDataFromDb extends AsyncTask<String, Void, Boolean> {

    @Override
    protected Boolean doInBackground(String... params) {
        dbOpenHelper = new DbOpenHelper(MainActivity.context);
        MainActivity.movies = dbOpenHelper.getAllFavoritePosters();
        return null;
    }

    @Override
    protected void onPostExecute(Boolean aBoolean) {
        super.onPostExecute(aBoolean);
        Log.v("database status", "Finished From Db");
        DbAdapter = new movieAdapter(context, R.layout.movie_item, MainActivity.movies);
        gridview.setAdapter(DbAdapter);
        if (MainActivity.isTablet()) {
            MainActivity.showDetails(0);
        }
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long ss) {
                MainActivity.showDetails(position);
            }
        });
    }
}
}

0 个答案:

没有答案