|
@@ -3,13 +3,16 @@ package com.example.mytest;
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
import android.graphics.Color;
|
|
import android.graphics.Color;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
+import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
|
+import org.w3c.dom.Text;
|
|
|
|
|
|
public class MainActivity extends Activity implements Interface {
|
|
public class MainActivity extends Activity implements Interface {
|
|
|
|
|
|
@@ -25,18 +28,52 @@ public class MainActivity extends Activity implements Interface {
|
|
LinearLayout news = findViewById(R.id.newContainer);
|
|
LinearLayout news = findViewById(R.id.newContainer);
|
|
|
|
|
|
try {
|
|
try {
|
|
- for (int i = 0; i < array.length(); i++) {
|
|
|
|
|
|
+ for (int i = array.length()-1; i >= 0; i--) {
|
|
|
|
|
|
JSONObject o = array.getJSONObject(i);
|
|
JSONObject o = array.getJSONObject(i);
|
|
|
|
|
|
|
|
+ // Контейнер под 1 новость
|
|
|
|
+ LinearLayout newsContainer = new LinearLayout(getApplicationContext());
|
|
|
|
+ LinearLayout.LayoutParams newsContainerLayout =
|
|
|
|
+ new LinearLayout.LayoutParams(
|
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
+ newsContainerLayout.bottomMargin = 20;
|
|
|
|
+ newsContainer.setLayoutParams(newsContainerLayout);
|
|
|
|
+ newsContainer.setBackgroundColor(Color.WHITE);
|
|
|
|
+ newsContainer.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
+
|
|
|
|
+ // Заголовок новости
|
|
TextView caption = new TextView(getApplicationContext());
|
|
TextView caption = new TextView(getApplicationContext());
|
|
|
|
+ LinearLayout.LayoutParams captionLayout =
|
|
|
|
+ new LinearLayout.LayoutParams(
|
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
+ captionLayout.setMargins(20, 20, 20, 20);
|
|
|
|
+ caption.setLayoutParams(captionLayout);
|
|
|
|
+ caption.setTextSize(20);
|
|
|
|
+ caption.setText(o.getString("Caption"));
|
|
|
|
+ caption.setPadding(0, 20, 0, 20);
|
|
|
|
+ caption.setTextColor(Color.rgb(50,50,50));
|
|
|
|
+ newsContainer.addView(caption);
|
|
|
|
+
|
|
|
|
+ // Текст новости
|
|
|
|
+ TextView preview = new TextView(getApplicationContext());
|
|
|
|
+ LinearLayout.LayoutParams previewLayout =
|
|
|
|
+ new LinearLayout.LayoutParams(
|
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
+ );
|
|
|
|
+ previewLayout.setMargins(20, 50, 20, 20);
|
|
|
|
+ preview.setLayoutParams(previewLayout);
|
|
|
|
+ preview.setText(o.getString("Preview"));
|
|
|
|
+ preview.setTextColor(Color.BLACK);
|
|
|
|
+ preview.setMaxLines(6);
|
|
|
|
+ preview.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
+ newsContainer.addView(preview);
|
|
|
|
+
|
|
|
|
+ news.addView(newsContainer);
|
|
|
|
|
|
- if (o.has("Caption")) {
|
|
|
|
- caption.setText(o.getString("Caption"));
|
|
|
|
- caption.setPadding(0, 20, 0, 20);
|
|
|
|
- caption.setTextColor(Color.RED);
|
|
|
|
- news.addView(caption);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|