Skip to content

Commit 465bd65

Browse files
Merge pull request #86 from dharanidharandharmasivam/master
sample browser changes.
2 parents 41bfbc7 + a5260a1 commit 465bd65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2021
-1011
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.syncfusion.flutter_examples">
3-
3+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
4+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
45
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
56
calls FlutterMain.startInitialization(this); in its onCreate method.
67
In most cases you can leave this as-is, but you if you want to provide
@@ -10,6 +11,15 @@
1011
android:name="io.flutter.app.FlutterApplication"
1112
android:label="Syncfusion Flutter UI Widgets"
1213
android:icon="@mipmap/ic_launcher">
14+
<provider
15+
android:name="androidx.core.content.FileProvider"
16+
android:authorities="${applicationId}.fileProvider"
17+
android:exported="false"
18+
android:grantUriPermissions="true">
19+
<meta-data
20+
android:name="android.support.FILE_PROVIDER_PATHS"
21+
android:resource="@xml/provider_path"/>
22+
</provider>
1323
<activity
1424
android:name=".MainActivity"
1525
android:launchMode="singleTop"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,76 @@
11
package com.syncfusion.flutter_examples;
22

3+
import android.Manifest;
4+
import android.content.Intent;
5+
import android.net.Uri;
6+
import android.os.Build;
37
import android.os.Bundle;
8+
9+
import androidx.core.app.ActivityCompat;
10+
import androidx.core.content.ContextCompat;
11+
import androidx.core.content.FileProvider;
12+
import androidx.core.content.PermissionChecker;
13+
14+
import java.io.File;
15+
416
import io.flutter.app.FlutterActivity;
17+
import io.flutter.plugin.common.MethodCall;
18+
import io.flutter.plugin.common.MethodChannel;
519
import io.flutter.plugins.GeneratedPluginRegistrant;
620

721
public class MainActivity extends FlutterActivity {
822
@Override
923
protected void onCreate(Bundle savedInstanceState) {
1024
super.onCreate(savedInstanceState);
1125
GeneratedPluginRegistrant.registerWith(this);
26+
new MethodChannel(getFlutterView(), "launchFile").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
27+
@Override
28+
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
29+
if (call.method.equals("viewPdf")) {
30+
String path = call.argument("file_path");
31+
if(!checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE)){
32+
requestPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE});
33+
} else {
34+
launchFile(path);
35+
}
36+
}
37+
}
38+
});
39+
}
40+
private void requestPermission(String[] permission){
41+
ActivityCompat.requestPermissions(this, permission, 1);
42+
}
43+
private boolean checkPermission(String permission) {
44+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
45+
return true;
46+
} else {
47+
if (ContextCompat.checkSelfPermission(this, permission) == PermissionChecker.PERMISSION_GRANTED) {
48+
return true;
49+
} else {
50+
return false;
51+
}
52+
}
53+
}
54+
private void launchFile(String filePath){
55+
File file = new File(filePath);
56+
if(file.exists()){
57+
Intent intent = new Intent(Intent.ACTION_VIEW);
58+
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
59+
intent.addCategory("android.intent.category.DEFAULT");
60+
Uri uri = null;
61+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
62+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
63+
String packageName = this.getPackageName();
64+
uri = FileProvider.getUriForFile(this, packageName + ".fileProvider", new File(filePath));
65+
}else {
66+
uri = Uri.fromFile(file);
67+
}
68+
intent.setDataAndType(uri, "application/pdf");
69+
try{
70+
this.startActivity(intent);
71+
}catch (Exception e){
72+
//Could not launch the file.
73+
}
74+
}
1275
}
1376
}

android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.flutter.plugins;
22

33
import io.flutter.plugin.common.PluginRegistry;
4+
import io.flutter.plugins.pathprovider.PathProviderPlugin;
45
import io.flutter.plugins.urllauncher.UrlLauncherPlugin;
56

67
/**
@@ -11,6 +12,7 @@ public static void registerWith(PluginRegistry registry) {
1112
if (alreadyRegisteredWith(registry)) {
1213
return;
1314
}
15+
PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"));
1416
UrlLauncherPlugin.registerWith(registry.registrarFor("io.flutter.plugins.urllauncher.UrlLauncherPlugin"));
1517
}
1618

assets/fonts/Montserrat-Bold.ttf

-255 KB
Binary file not shown.

assets/fonts/Montserrat-Medium.ttf

-254 KB
Binary file not shown.

images/code.png

518 Bytes
Loading

images/info.png

690 Bytes
Loading

ios/Runner/AppDelegate.m

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,43 @@
22
#include "GeneratedPluginRegistrant.h"
33

44
@implementation AppDelegate
5-
5+
UIDocumentInteractionController* _uiController;
66
- (BOOL)application:(UIApplication *)application
77
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
8+
FlutterViewController* controller =(FlutterViewController*) self.window.rootViewController;
9+
10+
FlutterMethodChannel* viewPdfFileChannel = [FlutterMethodChannel methodChannelWithName:@"launchFile" binaryMessenger: controller];
11+
12+
[viewPdfFileChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
13+
if ([@"viewPdf" isEqualToString:call.method]) {
14+
NSString* filePath = call.arguments[@"file_path"];
15+
NSFileManager* fileManager = [NSFileManager defaultManager];
16+
BOOL fileExist = [fileManager fileExistsAtPath:filePath];
17+
if(fileExist){
18+
NSString* fileExtension = [filePath pathExtension];
19+
_uiController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
20+
_uiController.delegate = self;
21+
if([fileExtension isEqualToString:@"pdf"]){
22+
_uiController.UTI = @"com.adobe.pdf";
23+
}
24+
else if([fileExtension isEqualToString:@"txt"]){
25+
_uiController.UTI = @"public.plain-text";
26+
}
27+
else{
28+
NSLog(@"The format %@ is not supported ", filePath);
29+
}
30+
@try {
31+
BOOL isPreview = [_uiController presentPreviewAnimated:YES];
32+
if(!isPreview){
33+
[_uiController presentOpenInMenuFromRect:CGRectMake(200, 20, 100, 100) inView: controller.view animated:YES];
34+
}
35+
36+
} @catch (NSException *exception) {
37+
NSLog(@"%@", exception);
38+
}
39+
}
40+
}
41+
}];
842
[GeneratedPluginRegistrant registerWithRegistry:self];
943
// Override point for customization after application launch.
1044
return [super application:application didFinishLaunchingWithOptions:launchOptions];

ios/Runner/GeneratedPluginRegistrant.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#import "GeneratedPluginRegistrant.h"
66

7+
#if __has_include(<path_provider/FLTPathProviderPlugin.h>)
8+
#import <path_provider/FLTPathProviderPlugin.h>
9+
#else
10+
@import path_provider;
11+
#endif
12+
713
#if __has_include(<url_launcher/FLTURLLauncherPlugin.h>)
814
#import <url_launcher/FLTURLLauncherPlugin.h>
915
#else
@@ -13,6 +19,7 @@
1319
@implementation GeneratedPluginRegistrant
1420

1521
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
22+
[FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]];
1623
[FLTURLLauncherPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTURLLauncherPlugin"]];
1724
}
1825

lib/model/model.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class SampleModel extends Model {
139139
Color bottomSheetBackgroundColor = Colors.white;
140140
final bool isTileView = true;
141141
Color cardThemeColor = Colors.white;
142+
bool isWeb = false;
142143

143144
void changeTheme(ThemeData _themeData) {
144145
themeData = _themeData;
@@ -185,8 +186,7 @@ class SampleModel extends Model {
185186
Future<void> updateControl() async {
186187
bool isSample = false;
187188
bool isChild = false;
188-
final String jsonText =
189-
await rootBundle.loadString('lib/sample_details.json');
189+
final String jsonText = await rootBundle.loadString('lib/sample_details.json');
190190
final List<dynamic> controlList = json.decode(jsonText);
191191
List<SubItem> subItems = <SubItem>[];
192192
List<SubItem> subItems1 = <SubItem>[];
@@ -243,7 +243,7 @@ class ChartSampleData {
243243
this.yValue3,
244244
this.pointColor,
245245
this.size,
246-
this.text});
246+
this.text,this.open,this.close});
247247
final dynamic x;
248248
final num y;
249249
final dynamic xValue;
@@ -253,4 +253,6 @@ class ChartSampleData {
253253
final Color pointColor;
254254
final num size;
255255
final String text;
256+
final num open;
257+
final num close;
256258
}

0 commit comments

Comments
 (0)